My first program in VB

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

    #16
    Originally posted by vdraceil
    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.
    I have done the same things as u said........ given command button for conversion; option buttons for selecting a no. system and has also provided text box for entering data.
    I dont know how to display that here.
    There doesnt come any option to copy the entire form...
    If u tell me how to do that i can display the form design over here.

    Comment

    • Parul Bagadia
      New Member
      • Mar 2008
      • 188

      #17
      can anybody plz tell me how do i attach my visual basic form over here?
      So that u can understand the form design and whatever is goin wrong.

      Comment

      • jg007
        Contributor
        • Mar 2008
        • 283

        #18
        Originally posted by Parul Bagadia
        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.
        Sorry, when I had used text2_change() that was as a call to the subroutine as I had slightly miss read the code but it was not very clear, please can you advise

        1. how the form is set up
        2. what you want to happen when the command button is clicked , including how the display changes


        I am really unclear what you are trying to achieve with this form but I have posted an example of some cut down code below that might help , again apologies if this is completely different to what you are trying to do!!

        also please note that I have not included any error checking for this so if you have this code and enter a string instead of a number into the box it will throw an exception also I don't have VB as I use vb.net so the subroutines may look a little different

        Code:
        Public Class Form1
        
        ' declare two integers used to hold the in number and out number 
        
            Dim inno As Integer
            Dim outno As Integer
        
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        
        ' when the button is clicked and the IF statement matches change outno to a value of inno x2 
        
                inno = Text1.Text
        
                If "A" = "A" And "B" = "B" Then
                    outno = inno * 2
        
        ' change text2.text to show outno
        
                    Text2.Text = outno
                End If
        
            End Sub
        
        End Class

        Comment

        • jg007
          Contributor
          • Mar 2008
          • 283

          #19
          sorry, my programming habits are probably not the best , I have just noticed the comment you made about the variables

          I am not really fully sure how it works but possibly it may do what you want if you use -

          Code:
             Private inno As Integer
             Private outno As Integer

          Comment

          • Parul Bagadia
            New Member
            • Mar 2008
            • 188

            #20
            Thanks a lot..
            In my program two text boxes are there; one to insert the number and other to display the result. One command button; which when clicked will perform actual conversion. And two frames to chose the number to be converted is in which number system as well the number to be obtained should be in which no. system with in all 6 option buttons..
            My code is now working for same system changes; where earlier it was not.
            What i mean by same system changes is........Base of input as well as output is the same may be octal/binary/hexadecimal.
            But now m getting some error while converting a no. from hexadecimal to binary.....
            The code is as follows:
            Code:
            Public outno As String
            Public inno As String
            Public Sub Text1_Change()
            inno = Text1.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 = hextobinary()
             End If
             
             Text2.Text = outno
            End Sub
            
            Public Sub Text2_Change()
             Text2.Text = outno
            End Sub
            Function hextobinary()
            Dim i As Integer
            Dim store As Long
            Dim reminder As String
            Dim quot As Integer
            Dim temp As String
            For i = 0 To 9
             If (inno(i) >= 0 And inno(i) <= 9) Then
              store = store + inno(i) * pow(16, i)
            
              ElseIf (inno(i) = a) Then
              inno(i) = 10
              store = store + inno(i) * pow(16, i)
              ElseIf (inno(i) = b) Then
              inno(i) = 11
              store = store + inno(i) * pow(16, i)
              ElseIf (inno(i) = c) Then
              inno(i) = 12
              store = store + inno(i) * pow(16, i)
              ElseIf (inno(i) = d) Then
              inno(i) = 13
              store = store + inno(i) * pow(16, i)
              ElseIf (inno(i) = d) Then
              inno(i) = 14
              store = store + inno(i) * pow(16, i)
              ElseIf (inno(i) = f) Then
              inno(i) = 15
              store = store + inno(i) * pow(16, i)
             End If
             Next i
            
            If store! = 0 Then
            i = 0
             Do
              reminder(i) = store Mod 2
              quot = store / 2
              i = i + 1
             While quot! = 0
            For j = 9 To 0
            outno(i) = reminder(j)
            i = i + 1
            j = j - 1
            Exit For
            Return
            End Function
            its showing some error as an array is expected.....
            I changed the data type of inno with array but there is no such data-type....

            Comment

            • Parul Bagadia
              New Member
              • Mar 2008
              • 188

              #21
              I understood, the error is because i have taken input in a number and accessing it as array in for loop.
              But then can somebody tell me how do i get my number in an array?.... there is no such data-type.. or is there?

              Comment

              • Parul Bagadia
                New Member
                • Mar 2008
                • 188

                #22
                In case of the function oct..it converts an expression to octal system number...can we have another number in some number system which can get converted in octal...

                Comment

                • jg007
                  Contributor
                  • Mar 2008
                  • 283

                  #23
                  you seem to be accessing inno as an array ie: array(no of item)

                  if you are trying to select as specific character within the string / integer you will be better using the MID command I think

                  lol please bear in mind that there may be better ways of doing this and I have not tried to work out the conversion but here is some code to split the string
                  Code:
                  For n = 1 To inno.Length
                  
                        value = (Mid(inno, n, 1))
                  
                  ' whatever it is that you wish to do with this value
                  
                  Next
                  to split it to an array -

                  Code:
                  dim value(inno.length) as string
                  
                  For n = 1 To inno.Length
                  
                        value(n) = (Mid(inno, n, 1))
                  
                  Next

                  Comment

                  • vdraceil
                    New Member
                    • Jul 2007
                    • 236

                    #24
                    i have designed a simple application which helps in base conversion..
                    but the problem is i dont know how to attach it here..
                    anyone knows how??

                    Comment

                    • Parul Bagadia
                      New Member
                      • Mar 2008
                      • 188

                      #25
                      Originally posted by vdraceil
                      i have designed a simple application which helps in base conversion..
                      but the problem is i dont know how to attach it here..
                      anyone knows how??
                      Even i have designed it. And even i dont know how ill post that here.......
                      Moreover i never asked for design..... M just gettin stuck somewhere in my code..

                      Comment

                      • vdraceil
                        New Member
                        • Jul 2007
                        • 236

                        #26
                        Originally posted by Parul Bagadia
                        Even i have designed it. And even i dont know how ill post that here.......
                        Moreover i never asked for design..... M just gettin stuck somewhere in my code..
                        As this is your first program in vb(and you have some difficulties with the coding),i thought you might need an example.. Do you need it? If yes i'll have to figure out a way..

                        Comment

                        • Parul Bagadia
                          New Member
                          • Mar 2008
                          • 188

                          #27
                          Originally posted by jg007
                          you seem to be accessing inno as an array ie: array(no of item)

                          if you are trying to select as specific character within the string / integer you will be better using the MID command I think

                          lol please bear in mind that there may be better ways of doing this and I have not tried to work out the conversion but here is some code to split the string
                          Code:
                          For n = 1 To inno.Length
                          
                                value = (Mid(inno, n, 1))
                          
                          ' whatever it is that you wish to do with this value
                          
                          Next
                          to split it to an array -

                          Code:
                          dim value(inno.length) as string
                          
                          For n = 1 To inno.Length
                          
                                value(n) = (Mid(inno, n, 1))
                          
                          Next
                          Am unable to do inno.length..
                          The compiler is showing error.
                          Is it the wrong way or sth else..

                          Comment

                          • Parul Bagadia
                            New Member
                            • Mar 2008
                            • 188

                            #28
                            Is pow function not there in VB? what do we do for exponential?

                            Comment

                            • Parul Bagadia
                              New Member
                              • Mar 2008
                              • 188

                              #29
                              I got how to do exponential thing........it s just by using[B] '^['/B].
                              But now can someone tell me how we use not equal to sign in VB?

                              Comment

                              • Parul Bagadia
                                New Member
                                • Mar 2008
                                • 188

                                #30
                                Originally posted by Parul Bagadia
                                I got how to do exponential thing........it s just by using[B] '^['/B].
                                But now can someone tell me how we use not equal to sign in VB?
                                I got that to by writting the expression in'( )' and using <> sign; but now m not getting equal to sign.

                                Comment

                                Working...