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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Apolakkiatis
    New Member
    • Jan 2008
    • 30

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

    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...

    Code:
    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.")
               [B] If X = vbCancel Then [/B] 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!!
    Last edited by Killer42; Jan 28 '08, 11:05 PM.
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    At first glance, I'd say variable X needs to be numeric. The MsgBox function returns a number, not a string.

    Comment

    • akashazad
      New Member
      • Sep 2007
      • 38

      #3
      Originally posted by Apolakkiatis
      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(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
      X = InputBox("Pleas e SET your PASSWORD for this application.")
      If X = vbCancel Then MsgBox("YOU HAVE TO SET A PASSWORD!")
      Do Until X = vbOKOnly
      X = InputBox("Pleas e 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(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click
      X = InputBox("Pleas e SET your PASSWORD for this application.")
      If X = vbCancel Then Exit Sub
      X = Chr(62)
      End Sub
      Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button2.Click
      R = InputBox("Pleas e 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

      Comment

      • Apolakkiatis
        New Member
        • Jan 2008
        • 30

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

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          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.
          Last edited by Killer42; Jan 29 '08, 02:45 AM. Reason: Corrected "stiry"

          Comment

          • Apolakkiatis
            New Member
            • Jan 2008
            • 30

            #6
            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!

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              Originally posted by Apolakkiatis
              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.


              Originally posted by Apolakkiatis
              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.

              Comment

              • Apolakkiatis
                New Member
                • Jan 2008
                • 30

                #8
                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

                Comment

                • daniel aristidou
                  Contributor
                  • Aug 2007
                  • 494

                  #9
                  Originally posted by Apolakkiatis
                  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....

                  Comment

                  • daniel aristidou
                    Contributor
                    • Aug 2007
                    • 494

                    #10
                    [CODE=vb]Public Class Form1
                    Dim X As long
                    'This is the command to use on the OK...button
                    Private Sub FormLogin_OK(By Val sender As System.Object, ByVal e As System.EventArg s) Handles Formlogin.click
                    If Textbox1.text = "" or isnumeric(Textb ox1.text) = False then

                    MsgBox("YOU HAVE TO SET A NUMERIC PASSWORD!")
                    Textbox1.Focus
                    Exit Sub

                    End if

                    X= Textbox1.text ' ie the textbox that recieves the password
                    Mainform.show 'Change main form with the form you want to load
                    me.hide

                    End sub

                    'I dont think this is advasiable it prevents exit from the program

                    Private Sub FormLogin_Cance l(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles Formlogin.cance l
                    MsgBox("YOU HAVE TO SET A PASSWORD!")
                    Textbox1.Focus 'ie the textbox that recieves the password

                    End sub

                    'instead of above I would use.......

                    Private Sub FormLogin_Cance l(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles Formlogin.cance l

                    Me.close

                    End sub
                    End Class [/CODE]

                    Comment

                    • Apolakkiatis
                      New Member
                      • Jan 2008
                      • 30

                      #11
                      Thanx man, you're greek ha? Euxaristw re file... 8a to dokhmasw!

                      Comment

                      • daniel aristidou
                        Contributor
                        • Aug 2007
                        • 494

                        #12
                        Originally posted by Apolakkiatis
                        Thanx man, you're greek ha? Euxaristw re file... 8a to dokhmasw!
                        Barakalw...... No problem

                        Comment

                        • Killer42
                          Recognized Expert Expert
                          • Oct 2006
                          • 8429

                          #13
                          Originally posted by daniel aristidou
                          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.
                          Last edited by Killer42; Jan 29 '08, 11:28 PM.

                          Comment

                          • Killer42
                            Recognized Expert Expert
                            • Oct 2006
                            • 8429

                            #14
                            Originally posted by Apolakkiatis
                            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.

                            Comment

                            • daniel aristidou
                              Contributor
                              • Aug 2007
                              • 494

                              #15
                              sorry killer......... ............... ...........

                              Comment

                              Working...