Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 24th, 2008, 7:42 PM   #1
kewlgeye
Programmer
 
Join Date: Jan 2008
Posts: 54
Rep Power: 1 kewlgeye is on a distinguished road
Unhappy Input Output Function Error

I am receiving an error. Conversion from string "" to type 'Double' is not valid.

I will show you the code. It seems to be coming from the variable that I was trying to create so that I could store the information from the sundaypm.txt file. And I wanted to compare it to that number that was stored in the file which is "15" and then to place the difference of that number and a number entered into the textbox in this particular form into another form called sundayResultsForm. Here is the code. Please help with this.


Public Class userForm

Friend cparecommendation
Friend cpaadminsundaycount


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


Dim messageString
Dim usersundayString As String = usersundaycpaTextBox.Text
Dim cpaMaxDecimal As Decimal = usersundayString - cpaadminsundaycount



If usersundaycpaTextBox.Text > cpaadminsundaycount Then
messageString = "You have " & cpaMaxDecimal & " player(s) available for hire."
cparecommendation = messageString
End If

' Open the file for output.

Dim fileReader As String
FileOpen(1, "Sundaypm.txt", OpenMode.Input)

fileReader = My.Computer.FileSystem.ReadAllText("Sundaypm.txt")
MsgBox(fileReader)
cpaadminsundaycount = MsgBox(fileReader)
sundayResultsForm.ShowDialog()


FileClose(1)




End Sub
End Class
kewlgeye is offline   Reply With Quote
Old Jan 24th, 2008, 8:07 PM   #2
Ghost
Man Bear Pig Hunter
 
Ghost's Avatar
 
Join Date: Jul 2005
Location: NorCal, USA
Posts: 295
Rep Power: 4 Ghost is on a distinguished road
Re: Input Output Function Error

Try CType.. that should help you out.
Ghost is offline   Reply With Quote
Old Jan 24th, 2008, 8:09 PM   #3
Ghost
Man Bear Pig Hunter
 
Ghost's Avatar
 
Join Date: Jul 2005
Location: NorCal, USA
Posts: 295
Rep Power: 4 Ghost is on a distinguished road
Re: Input Output Function Error

Also, next time, maybe a line number on where the error is...
Ghost is offline   Reply With Quote
Old Jan 24th, 2008, 9:20 PM   #4
kewlgeye
Programmer
 
Join Date: Jan 2008
Posts: 54
Rep Power: 1 kewlgeye is on a distinguished road
Red face Re: Input Output Function Error

Quote:
Originally Posted by Ghost View Post
Also, next time, maybe a line number on where the error is...

Thank you for your reply. I am not sure how to use the ctype, I visited the link but I don't know how or where or what to put in the example that I saw. But here is the error line


error. Conversion from string "" to type 'Double' is not valid.


The error is highlighting this line in the code
Dim cpaMaxDecimal As Decimal = usersundayString - cpaadminsundaycount

and pointing to "cpaadminsundaycount"
kewlgeye is offline   Reply With Quote
Old Jan 25th, 2008, 5:07 AM   #5
Ghost
Man Bear Pig Hunter
 
Ghost's Avatar
 
Join Date: Jul 2005
Location: NorCal, USA
Posts: 295
Rep Power: 4 Ghost is on a distinguished road
Re: Input Output Function Error

Dim cpaMaxDecimal As Decimal = CType(usersundayString, Decimal) - CType(cpaadminsundaycount, Decimal)

Is what you need. I'm a little drunk, but it looks good to me.
Ghost is offline   Reply With Quote
Old Jan 25th, 2008, 8:53 AM   #6
kewlgeye
Programmer
 
Join Date: Jan 2008
Posts: 54
Rep Power: 1 kewlgeye is on a distinguished road
Unhappy Re: Input Output Function Error

Quote:
Originally Posted by Ghost View Post
Dim cpaMaxDecimal As Decimal = CType(usersundayString, Decimal) - CType(cpaadminsundaycount, Decimal)

Is what you need. I'm a little drunk, but it looks good to me.
This is the error I am getting.

InvalidCastException was unhandled.
Conversion from string "" to type Decimal' is not valid

on the same line pointing to the same area "Ctype(cpaadminsundaycount, Decimal)

I'm stumped
kewlgeye is offline   Reply With Quote
Old Jan 25th, 2008, 9:16 AM   #7
kewlgeye
Programmer
 
Join Date: Jan 2008
Posts: 54
Rep Power: 1 kewlgeye is on a distinguished road
Re: Input Output Function Error

Quote:
Originally Posted by kewlgeye View Post
This is the error I am getting.

InvalidCastException was unhandled.
Conversion from string "" to type Decimal' is not valid

on the same line pointing to the same area "Ctype(cpaadminsundaycount, Decimal)

I'm stumped

Sorry, I think that it is line 15 from the original code above with the Ctype added instead.
kewlgeye is offline   Reply With Quote
Old Jan 25th, 2008, 2:56 PM   #8
Ghost
Man Bear Pig Hunter
 
Ghost's Avatar
 
Join Date: Jul 2005
Location: NorCal, USA
Posts: 295
Rep Power: 4 Ghost is on a distinguished road
Re: Input Output Function Error

What is teh value of "cpaadminsundaycount" ?
Ghost is offline   Reply With Quote
Old Jan 25th, 2008, 6:44 PM   #9
kewlgeye
Programmer
 
Join Date: Jan 2008
Posts: 54
Rep Power: 1 kewlgeye is on a distinguished road
Re: Input Output Function Error

Dim fileReader As String
FileOpen(1, "Sundaypm.txt", OpenMode.Input)

fileReader = My.Computer.FileSystem.ReadAllText("Sundaypm.txt")
MsgBox(fileReader)
cpaadminsundaycount = MsgBox(fileReader)
sundayResultsForm.ShowDialog()


The value is the number that I have in my Sundaypm.txt file which is 15
it actually shows in the file 15,

That number can change if the admin changes the number in a seperate form though.


I created the cpaadminsundaycount variable to store the MsgBox(fileReader) number that I think is 15 so that I can use it to do the math.
kewlgeye is offline   Reply With Quote
Old Jan 26th, 2008, 3:31 PM   #10
kewlgeye
Programmer
 
Join Date: Jan 2008
Posts: 54
Rep Power: 1 kewlgeye is on a distinguished road
Smile Re: Input Output Function Error

I figured it out. It took me a really long time but here is the solution to my problem.

' Open the Sunday file for output and declare variables.
Dim filereader As System.IO.StreamReader
filereader = My.Computer.FileSystem.OpenTextFileReader("Sundaypm.txt")
Dim stringReader As String
stringReader = filereader.ReadLine()
Dim asuncount As Decimal = stringReader

Dim cpaMaxDecimal As Decimal
Dim countaDecimal As Decimal
countaDecimal = asuncount - cpaTextBox.Text
cpaMaxDecimal = cpaTextBox.Text - asuncount


' Calculate Team A situation.
If cpaTextBox.Text < asuncount Then
messageString = "Team A is understaffed by " & countaDecimal & " player(s)."
.cparesponse = messageString
Else : .cparesponse = ""
End If
If cpaTextBox.Text > asuncount Then
messageString2 = ""
.cparesponse = messageString2
messageString3 = "You have " & cpaMaxDecimal & " player(s) available from Team A."
.cparecommendation = messageString3
Else : .cparecommendation = ""

End If
kewlgeye is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
C# corruption!!! Kilo C++ 32 May 21st, 2006 8:44 PM
Masm rsnd Assembly 4 May 20th, 2006 9:05 PM
Strange behavior: getting different results from the same input on a function. WTH? pulpfiction C 1 Mar 28th, 2006 11:43 PM
libraries matko C 1 Jan 22nd, 2006 2:12 PM
array function, error in arrays. cloud- C# 2 Nov 26th, 2005 11:23 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:09 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC