1.

Solve : VB 2008?

Answer»

I need some help with VB, I am new to programming and feel like I lost too many brain cells as teenager when I try to write my code. /sigh

Yes this is for a class but I am not asking for anyone to write it for me.. I need some clarification.
First I keep getting a SystemFormat Exception ( which I think basically means ERROR hehe)
it is when I am converting quantity to numeric values and using Parse.

I am confused as I wrote it exactly as the example in book ( well not exactly I changed the names to match my application) but I keep getting this error

We did cover Try, Catch As( well somewhat) so am I correct in assuming I should be using that to catch the Format Exceptions I am getting?



I really want to GO into Computer Science as my major( 2nd time around in COLLEGE for me) but yeeeesh I feel like if I can't get through VB I won't be able to do it

Thank you !Can you provide the code that is causing your issue?yes thank you!
QuantitySnowboardsInteger = Integer.Parse(SnowboardsTextBox.Text)
SnowboardsTextBox.Text = QuantitySnowboardsInteger.ToString()
QuantitySnowWBootInteger = Integer.Parse(SnowBootsTextBox.Text)
SnowBootsTextBox.Text = QuantitySnowWBootInteger.ToString()
This is before my calculations are performed.. again I did not add a Try Catch as Exception

The SystemFormat keeps highlighting this LINE. QuantitySnowWBootInteger = Integer.Parse(SnowBootsTextBox.Text)
Code: [Select] QuantitySnowWBootInteger = Integer.Parse(SnowBootsTextBox.Text)




Your issue is caused by the textbox not containing something the Parse() method accepts, so it throws an exception. (which, as you said, is an error)

To avoid the typing overhead of wrapping each Parse() method in a Try...Catch...Finally, you can use the Integer.TryParse() method; the line you have would look like this:

Code: [Select] If (Integer.TryParse(SnowBootsTextBox.Text,QuantitySnowWBootInteger)) Then
'QuantitySnowWBootInteger is now the proper value.
Else
'TryParse failed. (recommend prompt user to enter a valid number?
End If


However- if you are being taught Try...Catch Statements, it may have been an exercise in using Exception handling; if that's the case, you would stick with the Parse() Method, and wrap the Parse() calls in Exception handling, like so:

Code: [Select]Try
QuantitySnowWBootInteger = Integer.Parse(SnowBootsTextBox.Text)
Catch (SystemFormatException e)

'Error occured

End Try

(Not 100% wether that's proper syntax- believe it or not I don't program in .NET )

Hope this helps! Any questions? I gave up last night, watched BSG and went to bed. So I will try the above and see if that helps. It looks like it should.
As a matter of FACT I do have another question in regards to saving applications in VB. Am I doing something wrong? I save it to desktop or flashdrive depending on what I am doing. Yet when I open VB, its not always there? If I open the app from where I saved it I usually get an error that says Microsoft Visual Studio
---------------------------
One or more projects in the solution could not be loaded for the following reason(s):

The project file or web has been moved, renamed or is not on your computer.

These projects will be LABELED as unavailable in Solution Explorer. Expand the project node to show the reason the project could not be loaded.
-------------------------

Please no laughing) I know its probably obvious.. I either moved or renamed the file. But then sometimes when I click OK my app will open but I will be mising Solution Explorer.


I also learned the hard way NOT to open another VB application while working on one, or at least say NO to saving changes... The saving issue is common for people new to the whole "project" idiom- same thing occurs with VB6.

If you are using "Save Project As", for example, it will save a project file, but that project file is simply a list of the forms,modules, classes, and so forth that the project contains.

Instead of using "Save Project As", copy the folder your project is in to your flash drive. I'd recommend working from the flash drive, but I've learned via the loss of almost all of my code that that isn't a feasible solution.Ohhh I get it. That make sense as the ones that I can't open have been the ones I hit Save Project As to my desktop.

Thank you so much for your help. I really appreciate it
Quote from: Tourmaline on March 07, 2009, 05:21:33 PM

Ohhh I get it. That make sense as the ones that I can't open have been the ones I hit Save Project As to my desktop.

Thank you so much for your help. I really appreciate it


You're Welcome! Glad to be of some use!


Discussion

No Comment Found