By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,988 Members | 1,074 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,988 IT Pros & Developers. It's quick & easy.

I'm New to VB and Programming - I've only used Command Prompt

P: 30
Here is my scrpit,, when I try debugging it it keeps doing something stupid saying Conversion from string "" to type 'Double' is not valid. I will make the line it's refering to bold...

Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.     Dim X As String
  3.     Dim Password, PWord
  4.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  5.         X = InputBox("Please SET your PASSWORD for this application.")
  6.         If X = vbCancel Then MsgBox("YOU HAVE TO SET A PASSWORD!")
  7.         Do Until X = vbOKOnly
  8.             X = InputBox("Please SET your PASSWORD for this application.")
  9.             If X = vbCancel Then  MsgBox("YOU HAVE TO SET A PASSWORD!")
  10.             If X = vbOKOnly Then Show(Me)
  11.         Loop
  12.     End Sub
  13.     Dim R As String
  14.     Dim Z As String
  15.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  16.         X = InputBox("Please SET your PASSWORD for this application.")
  17.         If X = vbCancel Then Exit Sub
  18.         X = Chr(62)
  19.     End Sub
  20.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  21.         R = InputBox("Please Enter your Password")
  22.         If R = X Then MsgBox("You are cleared for entry!")
  23.         If R <> X Then MsgBox("Sorry WRONG Password, Nice Try...")
  24.     End Sub
  25. End Class


All that I have under the visual part are two buttons, one to set the password, and another to input it...

I'm trying to make it exit the MSGBOX and return to the INPUTBOX and loop, so that you have to put a value in for it, or it won't continue, SOMEONE PLZ help me (and if you attempt to explain it to me please try to explain it to me from scratch, because I have no clue what I'm doing and I'm new at this.)

THANX ALOT TO ANYONE WHO TRYS HELPING ME!!
Jan 27 '08 #1
Share this Question
Share on Google+
14 Replies


Expert 5K+
P: 8,434
At first glance, I'd say variable X needs to be numeric. The MsgBox function returns a number, not a string.
Jan 28 '08 #2

akashazad
P: 38
Here is my scrpit,, when I try debugging it it keeps doing something stupid saying Conversion from string "" to type 'Double' is not valid. I will make the line it's refering to bold...

Public Class Form1
Dim X As String
Dim Password, PWord
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
X = InputBox("Please SET your PASSWORD for this application.")
If X = vbCancel Then MsgBox("YOU HAVE TO SET A PASSWORD!")
Do Until X = vbOKOnly
X = InputBox("Please SET your PASSWORD for this application.")
If X = vbCancel Then MsgBox("YOU HAVE TO SET A PASSWORD!")
If X = vbOKOnly Then Show(Me)
Loop
End Sub
Dim R As String
Dim Z As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
X = InputBox("Please SET your PASSWORD for this application.")
If X = vbCancel Then Exit Sub
X = Chr(62)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
R = InputBox("Please Enter your Password")
If R = X Then MsgBox("You are cleared for entry!")
If R <> X Then MsgBox("Sorry WRONG Password, Nice Try...")
End Sub
End Class



All that I have under the visual part are two buttons, one to set the password, and another to input it...

I'm trying to make it exit the MSGBOX and return to the INPUTBOX and loop, so that you have to put a value in for it, or it won't continue, SOMEONE PLZ help me (and if you attempt to explain it to me please try to explain it to me from scratch, because I have no clue what I'm doing and I'm new at this.)

THANX ALOT TO ANYONE WHO TRYS HELPING ME!!




Reply :Please define your variable x as integer b/c VBCancel returns the neumeric value which is 3 which is for cancel button
Jan 28 '08 #3

P: 30
Conversion from string "SET" to type 'Integer' is not valid. is the reply I get when I "dim X as integer"
Jan 28 '08 #4

Expert 5K+
P: 8,434
Whoops! You've got a bit of a mess there. You're trying to use the same variable to accept the return value from InputBox, which returns a string, and MsgBox, which returns a number (probably Integer).

I recommend using separate variables. I also recommend not using the InputBox function, but that's another story.
Jan 28 '08 #5

P: 30
So how would I do that?

And is there a way to make another form on the same program and then link to that form, if so, how?

Thanx!
Jan 28 '08 #6

Expert 5K+
P: 8,434
So how would I do that?
How would you do what?

If you mean create separate variables, simply declare a String variable and an Integer variable (with different names, obviously). Use each of them where appropriate, rather than trying to use the one string for everything.


And is there a way to make another form on the same program and then link to that form, if so, how?
to create a new form, you just do whatever you did to create the first one. A VB project can contain a huge number of forms. (I can't tell you the specifics of how to create a form, as I work with a much older version and things have changed.)

As for "linking" them, it's just a question of what you want to do with them.
Jan 29 '08 #7

P: 30
Yea, i get that, but how does the program know that the INTEGER (Dimed as "X" lets say) is connected to the INPUTBOX (lets say "Y" that was Dimed as a String) That's what I don't get how to do... Because if i put Dim X as integer and Dim Y as string then i would put Y = inputbox("blah......") but how does it know that X is the integer for the Y inputbox? I can't get it to do that
Jan 29 '08 #8

daniel aristidou
100+
P: 491
Yea, i get that, but how does the program know that the INTEGER (Dimed as "X" lets say) is connected to the INPUTBOX (lets say "Y" that was Dimed as a String) That's what I don't get how to do... Because if i put Dim X as integer and Dim Y as string then i would put Y = inputbox("blah......") but how does it know that X is the integer for the Y inputbox? I can't get it to do that
From the look of your code it looks like you are using vb08 or vb2k5
Any way.....forget about input boxes........
You Should create your own input box....I suggest a login form.....
Go to add new items.....
Add new form
Login form.......
Customize it.........
Use the code i post in next post....
Jan 29 '08 #9

daniel aristidou
100+
P: 491
Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2. Dim X As long
  3. 'This is the command to use on the OK...button 
  4. Private Sub FormLogin_OK(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Formlogin.click
  5. If Textbox1.text = "" or isnumeric(Textbox1.text) = False then
  6.  
  7. MsgBox("YOU HAVE TO SET A NUMERIC PASSWORD!")
  8. Textbox1.Focus
  9. Exit Sub
  10.  
  11. End if
  12.  
  13. X= Textbox1.text ' ie the textbox that recieves the password
  14. Mainform.show 'Change main form with the form you want to load
  15. me.hide 
  16.  
  17. End sub
  18.  
  19. 'I dont think this is advasiable it prevents exit from the program
  20.  
  21. Private Sub FormLogin_Cancel(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Formlogin.cancel
  22. MsgBox("YOU HAVE TO SET A PASSWORD!")
  23. Textbox1.Focus 'ie the textbox that recieves the password
  24.  
  25. End sub
  26.  
  27. 'instead of above I would use.......
  28.  
  29. Private Sub FormLogin_Cancel(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Formlogin.cancel
  30.  
  31. Me.close
  32.  
  33. End sub
  34. End Class 
Jan 29 '08 #10

P: 30
Thanx man, you're greek ha? Euxaristw re file... 8a to dokhmasw!
Jan 29 '08 #11

daniel aristidou
100+
P: 491
Thanx man, you're greek ha? Euxaristw re file... 8a to dokhmasw!
Barakalw...... No problem
Jan 29 '08 #12

Expert 5K+
P: 8,434
Barakalw...... No problem
Come on people, English only or I'll have to start deleting posts.

If you want to chat in Greek, please do so via Private Message. The posting guidelines require English in the forums.
Jan 29 '08 #13

Expert 5K+
P: 8,434
Yea, i get that, but how does the program know that the INTEGER (Dimed as "X" lets say) is connected to the INPUTBOX (lets say "Y" that was Dimed as a String) That's what I don't get how to do... Because if i put Dim X as integer and Dim Y as string then i would put Y = inputbox("blah......") but how does it know that X is the integer for the Y inputbox? I can't get it to do that
Why would you expect VB to "know" which variable is intended for what purpose?

You use the Integer where an Integer is required, and the String where a String is required.

MsgBox returns an Integer, so you use X there. InputBox returns a String, so you use Y. There's no connection between the two.
Jan 29 '08 #14

daniel aristidou
100+
P: 491
sorry killer...................................
Jan 30 '08 #15

Post your reply

Sign in to post your reply or Sign up for a free account.