View Full Version : Vb.net help
Torres
13-02-2010, 08:03 AM
I am trying to make a basic converter program on VB.Net however I am having a bit of difficulty as I am very inexperienced with code. I am trying to make a converter so that when you enter a value into one text box, it should output another in another text box.
I am trying to do: Text2 = Text1 multiplied by 5 then divided by 8.
However I have no idea as to what to do!
Cheers.
doug7131
13-02-2010, 10:17 PM
textbox2.text = textbox1.text * 5 / 8
(make sure to set the defult text in the textbox's to 0)
Helior
13-02-2010, 10:34 PM
There are a number of approaches depending on how string you want the code to be
the simplest is probably to bind the leave event with the following (to binf the leave even you can select the text box, then in the properties pane, select the lightning bolt, this shows all events, you can then double click an even to create an event handler method stub.)
Private Sub TextBox1_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.Leave
TextBox2.Text = TextBox1.Text * 5 / 8
End Sub
But it's sloppy you should really parse first.
Dim number as Integer
If (Integer.TryParse(TextBox1.Text, number)) Then
TextBox2.Text = number * 5 / 8
Else
TextBox2.Text = "Invalid entry"
End If
Even better would be to use an error provider to validate tb1 then bind on the validated event.
note: I don't speak VB so the syntax is likely wrong somewhere! if you are a beginner i'd really suggest the c# route, much nicer syntax and it is undoubtedly the future.
Torres
14-02-2010, 01:55 PM
I have managed to get it to convert miles into kilometres, I have now however incoporated a switch button so it switches the km and miles so km is at the top and miles is at the bottom however I cannot get it to convert km into miles. I have made a new command button which is hidden until the switch button is pressed, and reveresed the code of the orignal command button to the new one however it does not do anything!
Suggestions?
Cheers.
jonbanjo
14-02-2010, 02:55 PM
note: I don't speak VB so the syntax is likely wrong somewhere! if you are a beginner i'd really suggest the c# route, much nicer syntax and it is undoubtedly the future.
Re syntax,would I be alone in liking Pascal?
Helior
14-02-2010, 03:39 PM
pascal is OK, i've not used it much, it's only really VB that i dislike, it's excessively verbose.
Torres, provide more info on exactly what you want and your code so far i'll happily help you, although my code will have a c# slant :p
jonbanjo
14-02-2010, 05:26 PM
You 'd beO kwith C then?
Torres
14-02-2010, 08:31 PM
Well thanks for the help guys :) I managed to finish the program which I am actually rather pleased with :P
Cheers.
Mungo
14-02-2010, 09:45 PM
Well thanks for the help guys :) I managed to finish the program which I am actually rather pleased with :P
Cheers.
Send me a copy? :D
Mr. Orange
14-02-2010, 10:48 PM
Send me a copy? :D
send me one too :D
Torres
16-02-2010, 11:44 AM
Ha ok, when I am back at home which is tomorow, however it is still poor and lots of things need smoothing out :P
Kremmen
17-02-2010, 06:17 AM
Like many others I'm still using VB6.
I've dabbled with VB.NET but it's just so complicated in comparison.
Helior
17-02-2010, 07:49 AM
Like many others I'm still using VB6.
I've dabbled with VB.NET but it's just so complicated in comparison.
Ah come one, it's not that much more complicated, most stuff is actually easier and clearer imo. Just take the plunge!
Kremmen
18-02-2010, 06:03 AM
:) If the client wants to pay for all our apps to be converted then fine.
We had a dabble at converting some of the simpler ones and it didn't want to know.
The Microsoft conversion tool isn't exactly helpful when it doesn't know what a VB6 CommonDialog is !!
Torres
19-02-2010, 01:32 PM
I now want it to return an error message when anything which isn't a number is entered. I have had a play however am not sure what to put to define anything which isn't a real number.
If Text1.Text Then MessageBox.Show("ERROR")
If I put for isnatce "Text1.Text <15 Then MessageBox.Show("ERROR")
That works fine but of course I do not want it to do this :p
Cheers.
Kremmen
22-02-2010, 07:07 AM
I'm coming at you from a VB6 perspective which may or may not work in .net
Have a look at the 'like' statement.
If text1.text Like "*[!0-9]*" then..........
or
can you use MaskEdBox's in .net, they allow pre determined formats.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.