My first program in VB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Parul Bagadia
    New Member
    • Mar 2008
    • 188

    #1

    My first program in VB

    Hi people..... this is my first program in VB.
    Before this i have done programming in C,C++.
    I read some of the chapters from Black book of VB; but still having problem in the initial part itself.
    The program is I have to take a number in any of the forms; Octal, binary or hexadecimal convert it in the form required by user and display the result.
    Am done with the logic of program; but having problems..
    Code:
    Private Sub Form_Load()
    
    Dim intext As String
    intext = Text1.Text
    
    Dim outtext As String
    outtext = Text2.Text
    if (option1.Value=true) and (option4.Value=true)
    outtext = intext
    End If
    
    
    
    
    
    
    End Sub
    First of all am not understanding why it creates so many procedures; every time i click something...... .
    And its showing error in if statement dont know why..
    Is it because of option? i deleted some sub procedures above it; before that also it was showing an error.
    Am using Microsoft Visual Basic.
    Please tell me fast.
  • Parul Bagadia
    New Member
    • Mar 2008
    • 188

    #2
    Sorry folks, i troubled u i got the mistake; i had forgotten to write THEN.
    But u can still tell me what's the use of different procedures; which we get when we click any of the controls?
    I mean are they private? or public? Are they excluded from other code?
    What if we dont make them?

    Comment

    • vdraceil
      New Member
      • Jul 2007
      • 236

      #3
      Originally posted by Parul Bagadia
      Sorry folks, i troubled u i got the mistake; i had forgotten to write THEN.
      But u can still tell me what's the use of different procedures; which we get when we click any of the controls?
      I mean are they private? or public? Are they excluded from other code?
      What if we dont make them?
      In visual basic,when you just double-click a control,it automatically enters the code window creating the procedure for the basic event of the control you clicked..for example,if you double click command button,it creates a procedure Command1_Click, because click is the most usual event one will perform on a command button.if you want some other event you can choose in the code window.

      This feature makes the task of developers easier.If you dont want to write anything inside the created procedure,just leave it or if you still feel annoying delete it.(Try not to double click any of the unnecessary controls in design time).

      Since you are a beginner,you may feel this annoying,but once you get involved with visual basic,you'd really love this feature-it saves your time!

      Remember visual basic does an event driven programming.

      Comment

      • Parul Bagadia
        New Member
        • Mar 2008
        • 188

        #4
        It's the same program; where i got to convert a number from one number system to another..... m a bit confused regarding scope of different variables.
        Here is my program that i wrote in Microsoft Visual Basic 6.0; for now its having only 3 options and that too converting a number from one to same number system.. Not actually converting also.. but its not displaying anything in text2.
        Here is the code.I dont know how will i copy the form of VB.

        Public Sub Text1_Change()
        Static inno As Integer
        inno = Text1.Text
        End Sub

        Public Sub Text2_Change()
        Static outno As Integer
        outno = Text2.Text
        End Sub

        Public Sub Command1_Click( )

        If Option1.Value = True And Option4.Value = True Then
        outno = inno
        End If

        If Option2.Value = True And Option5.Value = True Then
        outno = inno
        End If

        If Option3.Value = True And Option6.Value = True Then
        outno = inno
        End If

        'If Option1.Value = True And Option6.Value = True Then
        'outno = inno
        'End If
        'Dim counter As Integer
        'For counter = 0 To 9
        End Sub

        Comment

        • Parul Bagadia
          New Member
          • Mar 2008
          • 188

          #5
          Originally posted by vdraceil
          In visual basic,when you just double-click a control,it automatically enters the code window creating the procedure for the basic event of the control you clicked..for example,if you double click command button,it creates a procedure Command1_Click, because click is the most usual event one will perform on a command button.if you want some other event you can choose in the code window.

          This feature makes the task of developers easier.If you dont want to write anything inside the created procedure,just leave it or if you still feel annoying delete it.(Try not to double click any of the unnecessary controls in design time).

          Since you are a beginner,you may feel this annoying,but once you get involved with visual basic,you'd really love this feature-it saves your time!

          Remember visual basic does an event driven programming.
          Thanks.
          But m not sure whether i understand the meaning of event driven programming.

          Comment

          • jg007
            Contributor
            • Mar 2008
            • 283

            #6
            Originally posted by Parul Bagadia

            Here is the code.I dont know how will i copy the form of VB.

            Public Sub Text1_Change()
            Static inno As Integer
            inno = Text1.Text
            End Sub

            Public Sub Text2_Change()
            Static outno As Integer
            outno = Text2.Text
            End Sub

            Public Sub Command1_Click( )

            If Option1.Value = True And Option4.Value = True Then
            outno = inno
            End If

            End Sub
            I have chopped your code a little for size but looking at it you do not seem to be calling the Text2_Change sub inorder to change the text so all the program does when you click on the command1 is set the value of outno

            also you are declaring the integers whenever you call the text change subs which does not look correct

            i think if i understand what you are trying to do you will need to have something like -

            Public Sub Command1_Click( )

            If Option1.Value = True And Option4.Value = True Then
            outno = inno
            End If

            Text2_Change()

            End Sub

            Comment

            • Parul Bagadia
              New Member
              • Mar 2008
              • 188

              #7
              Please reply fast. I'm stuck with first program itself.

              Comment

              • vdraceil
                New Member
                • Jul 2007
                • 236

                #8
                Originally posted by Parul Bagadia
                Thanks.
                But m not sure whether i understand the meaning of event driven programming.
                vb reacts to every possible event occuring to any control in the form.if it is a command button it may be subjected to many possible events like click,double click,mouse move etc. And the users can make their own coding under any event they wish to monitor.
                This kind of programming is event driven programming.

                Comment

                • Parul Bagadia
                  New Member
                  • Mar 2008
                  • 188

                  #9
                  Originally posted by vdraceil
                  vb reacts to every possible event occuring to any control in the form.if it is a command button it may be subjected to many possible events like click,double click,mouse move etc. And the users can make their own coding under any event they wish to monitor.
                  This kind of programming is event driven programming.
                  thank you so much...
                  Can u plz tell me wats wrong with my code?

                  Comment

                  • vdraceil
                    New Member
                    • Jul 2007
                    • 236

                    #10
                    Originally posted by Parul Bagadia
                    Please reply fast. I'm stuck with first program itself.
                    to display something in textbox2 u must have text2.text=some value(i mean text2.text must be on the left side-assignment is from right to left)..
                    Why use static variables and declare it inside text box change event?instead you can declare variables generally(outsi de all events-so that the variables become public to the entire form)

                    Comment

                    • Parul Bagadia
                      New Member
                      • Mar 2008
                      • 188

                      #11
                      Originally posted by jg007
                      I have chopped your code a little for size but looking at it you do not seem to be calling the Text2_Change sub inorder to change the text so all the program does when you click on the command1 is set the value of outno

                      also you are declaring the integers whenever you call the text change subs which does not look correct

                      i think if i understand what you are trying to do you will need to have something like -

                      Public Sub Command1_Click( )

                      If Option1.Value = True And Option4.Value = True Then
                      outno = inno
                      End If
                      Text2_Change()

                      End Sub
                      Thanks budy.
                      May be because m new in VB, i didnt understand why do i hav to keep it blank the text2 event?
                      And wats wrong with integer?
                      I mean earlier i had used string and instead of text i had used text1.text but i was getting a error that i cannot assign it to an array... M not sure wether i got that.

                      Comment

                      • Parul Bagadia
                        New Member
                        • Mar 2008
                        • 188

                        #12
                        Originally posted by vdraceil
                        to display something in textbox2 u must have text2.text=some value(i mean text2.text must be on the left side-assignment is from right to left)..
                        Why use static variables and declare it inside text box change event?instead you can declare variables generally(outsi de all events-so that the variables become public to the entire form)
                        But then that will be global if m not wrong... and its not a good programming practise to declare variables as global.... so m willing to avoid that habit from beginning itself......... otherwise later it causes problems.

                        Comment

                        • Parul Bagadia
                          New Member
                          • Mar 2008
                          • 188

                          #13
                          Originally posted by vdraceil
                          to display something in textbox2 u must have text2.text=some value(i mean text2.text must be on the left side-assignment is from right to left)..
                          Why use static variables and declare it inside text box change event?instead you can declare variables generally(outsi de all events-so that the variables become public to the entire form)
                          I did text2.text=outn o.. but still invain.

                          Comment

                          • Parul Bagadia
                            New Member
                            • Mar 2008
                            • 188

                            #14
                            I also used debugger but all that m gettin in here is this:
                            For all the text boxes, options, variables no value is getting displayed other than the message: expression not defined in context for inno and for rest ; out of context..
                            Why is it so?

                            Comment

                            • vdraceil
                              New Member
                              • Jul 2007
                              • 236

                              #15
                              Originally posted by Parul Bagadia
                              I also used debugger but all that m gettin in here is this:
                              For all the text boxes, options, variables no value is getting displayed other than the message: expression not defined in context for inno and for rest ; out of context..
                              Why is it so?
                              Are you sure that you made the right calculations for converting numbers(you didnt show that in your code) and stored it in outno?
                              Better have a command button so that the user may click it after entering the number in the text box and selecting the conversion type option button. Finally include text2.text=outn o in command button's click event.

                              Okay..just give me some time and i'll design the proj and attach it.

                              Comment

                              Working...