Need Help? Visual Basic Help Here!

Discussion in 'Programming General' started by Visual Basic Matt, Feb 1, 2008.

Need Help? Visual Basic Help Here!
  1. Unread #1 - Feb 1, 2008 at 7:15 PM
  2. Visual Basic Matt
    Joined:
    Jan 29, 2008
    Posts:
    647
    Referrals:
    2
    Sythe Gold:
    56
    Discord Unique ID:
    223154494878253056

    Visual Basic Matt Apprentice

    Need Help? Visual Basic Help Here!

    Visual Basic Is Realllllly Easy when you get to know how to do it! It Is Not hard at All to get the hang of it! I will give you as many tips as i can right now just to give you a good start with visual basic.
    For example
    A Simple Calculator
    Code:
    Private Sub Command1_Click()
    Dim lsOperand1 As Single
    Dim lsOperand2 As Single
    Dim lsResult As Single
    lsOperand1 = Val(txtOperand1.Text)
    lsOperand2 = Val(txtOperand2.Text)
    lsResult = lsOperand1 + lsOperand2
    Label1.Caption = lsResult
    'Check entrys if numeric
    If Not IsNumeric(txtOperand1.Text) Then
    MsgBox "Please Enter A *Number*"
    End If
    End Sub
    
    Private Sub Command2_Click()
    Dim lsOperand1 As Single
    Dim lsOperand2 As Single
    Dim lsResult As Single
    lsOperand1 = Val(txtOperand1.Text)
    lsOperand2 = Val(txtOperand2.Text)
    lsResult = lsOperand1 - lsOperand2
    Label1.Caption = lsResult
    'Check entrys if numeric
    If Not IsNumeric(txtOperand1.Text) Then
    MsgBox "Please Enter A *Number*"
    End If
    End Sub
    
    Private Sub Command3_Click()
    Dim lsOperand1 As Single
    Dim lsOperand2 As Single
    Dim lsResult As Single
    lsOperand1 = Val(txtOperand1.Text)
    lsOperand2 = Val(txtOperand2.Text)
    lsResult = lsOperand1 * lsOperand2
    Label7.Caption = lsResult
    'Check entrys if numeric
    If Not IsNumeric(txtOperand1.Text) Then
    MsgBox "Please Enter A *Number*"
    End If
    End Sub
    All You Need is...
    2text boxes
    3Buttons
    And 1 label
    It Is Easy To Make The Buttons And Stuff
    The Harder Part Is The Code
    It Is Really not that hard.

    Another Example...
    Make 1 Label
    Make 1 Button
    Click On The Button For The Code
    It Should Look Like This
    Code:
    Private Sub Command1_Click()
    
    End Sub
    In Between Private Sub Comm... And End Sub
    Type In This Code
    label1.text = "Hello"
    Then Run It And The Text Should Change to Hello
    Not Much But It Is A Start.
    Study The Next Code...

    Code:
    Dim yourscore As Byte
    Dim computerscore As Byte
    Dim upperlimit As Integer
    Dim lowerlimit As Integer
    
    Public Function GenerateRandomNumber(ByVal LowestLimit As Integer, ByVal HighestLimit As Integer) As Integer
    
    GenerateRandomNumber = ((HighestLimit - LowestLimit + 1) * Rnd) + LowestLimit
    
    End Function
    
    
    Private Sub Command1_Click()
    Dim x As Byte
    
    'Check entry if numeric
    If Not IsNumeric(Text1.Text) Then
    MsgBox "Please Enter a Number 1-9999"
    Text1.Text = ""
    Exit Sub
    End If
    
    'Generate random number
    Randomize
    x = GenerateRandomNumber(lowerlimit, upperlimit)
    
    'Display the random number at Label2
    Label2.Caption = CStr(x)
    
    'Choose the winner and add points to who ever wins
    If (x > CInt(Text1.Text)) Then
    
    computerscore = computerscore + 1
    'Display Computer score at label3
    Label3.Caption = CStr(computerscore)
    
    ElseIf (x < CInt(Text1.Text)) Then
    
    yourscore = yourscore + 1
    'Display your score at label1
    Label1.Caption = CStr(yourscore)
    
    Else
    
    MsgBox "Tie!"
    Exit Sub
    End If
    
    If yourscore = 10 Then
    
    MsgBox "You WIN! Wow Nice Job!"
    End
    ElseIf computerscore = 10 Then
    
    MsgBox "Computer Wins (So Sad...)"
    End
    End If
    
    
    
    End Sub
    
    Private Sub Command2_Click()
    Command2.Caption = "Well, Its Simple... You Type In The Text Box A 4 **** Number. Anything Like 1-9999 You Put In A Different Number Each Try Or Just Keep The Same Number. Its Is Easy And Enjoy (Luck)"
    End Sub
    
    Private Sub Form_Load()
    
    Command1.Caption = "Start"
    Text1.Text = ""
    Label1.Caption = ""
    Label2.Caption = ""
    Label3.Caption = ""
    
    computerscore = 0
    yourscore = 0
    
    
    'sets the highest number possible for random number generation
    upperlimit = 99
    'sets the lowest number possible for random number generation
    lowerlimit = 0
    
    
    End Sub
    
    
     
    Using This Code You Can Create A Game!
    More Of A Card Game...
    All You Need Is To...

    Create 3 Label object position it in a form
    Create 1 textbox and 1 button
    Label1 is your score
    Label2 is where the random number generated will be displayed
    Label3 is where you display the computer score
    The First Score To 10 Is The Winner.
    You Can Change The Code A little Bit Like What Number It Must Be To Win.
    Now Try To Make Something out of this code.
    Remember To Add The Buttons,TextBoxes,ect With The Right Name Or Just Change the Name On The Code. Here It Is...


    Code:
    Private Sub cmdAddToList_Click()
        AddItem txtData.Text
    End Sub
    
    
    Private Sub Form_Load()
        Me.Caption = Me.Caption & " v." & App.Major & "." & App.Minor & "." & App.Revision
        clearList
    End Sub
    
    Private Sub clearList()
    
        Erase strLIST
        
        iListCount = 0
        
        iTopIndex = 0
        
        iListIndex = -1
        
        lblSelectInfo.Caption = "                   "
        
        scrollV.Max = 0
        
        scrollH.Max = 0
        
        picList_Resize
        
        updateList
        
        
        ' Assumed that we are using fixed font:
        iCharWidth = picList.TextWidth("W")
        iCharHeight = picList.TextHeight("W")
        
    End Sub
    
    Private Sub AddItem(sItem As String)
    Dim iTW As Integer
    Dim iSC As Integer
    Dim sTEMP As String
    Dim i As Integer
    
        ReDim Preserve strLIST(0 To iListCount)
        
        strLIST(iListCount) = sItem
        
        iListCount = iListCount + 1
    
        scrollV.Max = iListCount
    
        sTEMP = remove_ALL_COLOR_DATA(sItem)
    
        iTW = picList.TextWidth(sTEMP)
        
        If iWorkingWidth < iTW Then
        
            iSC = iTW - iWorkingWidth
                    
            i = iSC / iCharWidth
            
            If (iSC Mod iCharWidth) > 0 Then iSC = 1  ' remainder converted to full char.
    
            iSC = iSC + i
    
            If iSC > scrollH.Max Then
                scrollH.Max = iSC
            End If
            
        End If
    
        updateList
        
    End Sub
    
    Private Sub updateList()
    Dim i As Integer
    Dim s As String
    
        picList.Cls
        
        For i = iTopIndex To iListCount - 1
        
            s = strLIST(i)
            
            picList.CurrentX = -iHorScrollVal * iCharWidth
            
            ' for some reason, the horizontal scroll doesn't do
            ' its work nice without it:
            If iHorScrollVal > 0 Then
                picList.CurrentX = picList.CurrentX - iCharWidth
            End If
            
            If i = iListIndex Then
                draw_SELECTOR
            End If
            
            print_in_COLOR s
        
            ' no need to print items that aren't visible:
            If picList.CurrentY > iWorkingHeight Then
                ' Debug.Print "stopped at: " & strLIST(i)
                Exit For
            End If
        
        Next i
    
        draw_BOX
        
    End Sub
    
    Private Sub print_in_COLOR(sExpr As String)
    
    Dim l As Long
    Dim lExprLen As Long
    Dim s As String
    Dim c As String
    
    lExprLen = Len(sExpr)
    
    s = ""
    l = 1  ' string starts at index 1.
    
    picList.ForeColor = COLOR_DEFAULT
    
    Do While l <= lExprLen
    
        c = Mid(sExpr, l, 1)
        
        If c = "\" Then
            
            If Len(s) > 0 Then
                picList.Print s;
                s = ""
            End If
            
            
            l = l + 1
            c = Mid(sExpr, l, 1) ' get color code.
            
            If c = "\" Then
                picList.Print "\";
            Else
                picList.ForeColor = QBColor(Val("&H" & c))
            End If
            
        Else
        
            s = s & c
            
        End If
    
        l = l + 1
        
    Loop
    
    If Len(s) > 0 Then
        picList.Print s
    Else
        picList.Print   ' just new line.
    End If
    
    End Sub
    
    
    ' this function parses the string the same way as
    ' print_in_COLOR() does, and returns string without any
    ' controlling characters:
    Private Function remove_ALL_COLOR_DATA(sExpr As String) As String
    
    Dim l As Long
    Dim lExprLen As Long
    Dim s As String
    Dim c As String
    Dim sRESULT As String
    
    lExprLen = Len(sExpr)
    
    sRESULT = ""
    s = ""
    l = 1  ' string starts at index 1.
    
    picList.ForeColor = COLOR_DEFAULT
    
    Do While l <= lExprLen
    
        c = Mid(sExpr, l, 1)
        
        If c = "\" Then
            
            If Len(s) > 0 Then
                sRESULT = sRESULT & s
                s = ""
            End If
            
            l = l + 1
            
            c = Mid(sExpr, l, 1) ' get color code.
            
            If c = "\" Then
                sRESULT = sRESULT & "\"
            End If
            
        Else
        
            s = s & c
            
        End If
    
        l = l + 1
        
    Loop
    
    If Len(s) > 0 Then sRESULT = sRESULT & s
    
    
    remove_ALL_COLOR_DATA = sRESULT
    
    End Function
    
    
    
    Private Sub scrollH_Change()
        scrollH_Scroll
    End Sub
    
    Private Sub scrollH_Scroll()
        iHorScrollVal = scrollH.Value
        updateList
    End Sub
    
    Private Sub scrollV_Change()
        scrollV_Scroll
    End Sub
    
    Private Sub scrollV_Scroll()
        iTopIndex = scrollV.Value
        updateList
    End Sub
    
    
    
    
    Private Sub picList_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim iTEMP As Integer
    
    iTEMP = Fix(Y / iCharHeight)
    
    iTEMP = iTEMP + iTopIndex
    
    If iTEMP < iListCount Then
    
        iListIndex = iTEMP
    
        lblSelectInfo.Caption = " Selected Item: " & iListIndex & " "
        
        updateList
        
    End If
    
    End Sub
    
    ' selection also works when mouse is moving while
    ' left button is pressed:
    Private Sub picList_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If Button = vbLeftButton Then
            picList_MouseDown Button, Shift, X, Y
        End If
    End Sub
    
    ' Draws little box in the right
    ' lower corner between scroll bars:
    Private Sub draw_BOX()
        picList.Line (scrollH.Width, scrollV.Height)-(picList.ScaleWidth, picList.ScaleHeight), vb3DFace, BF
    End Sub
    
    ' Draws item selector of selected
    ' list item:
    Private Sub draw_SELECTOR()
        Dim fORIG_cX As Single
        Dim fORIG_cY As Single
        
        ' remember original current X/Y:
        fORIG_cX = picList.CurrentX
        fORIG_cY = picList.CurrentY
        
        picList.Line (0, fORIG_cY)-(iWorkingWidth, fORIG_cY + iCharHeight), COLOR_SELECTOR, BF
        
        ' restore original current X/Y:
        picList.CurrentX = fORIG_cX
        picList.CurrentY = fORIG_cY
    End Sub
    
    Private Sub cmdClearList_Click()
        clearList
    End Sub

    Now You Should No A Little Bit More Abount Visual Basic
    It Is Really Easy.
    You Cant Say Its Hard.

    Post Any Questions You Have.
    Also Try And Answer Peoples Questions If You Can!
     
  3. Unread #2 - Feb 8, 2008 at 12:26 AM
  4. demonavenger
    Joined:
    Feb 25, 2007
    Posts:
    536
    Referrals:
    0
    Sythe Gold:
    0

    demonavenger Forum Addict
    $5 USD Donor

    Need Help? Visual Basic Help Here!

  5. Unread #3 - Feb 8, 2008 at 1:17 AM
  6. Covey
    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Need Help? Visual Basic Help Here!

    You should not be teaching other people visual basic, because of the following reasons;
    - You copy & paste code and act as if it's your own.
    - That coding is poorly displayed.
    - You're declaring variables as one type then forcing another similar variable into it. (example in your calculator code you are forcing a double into a single, the problem with that is single variables do not include the decimal placing. You probably won't even understand this as its not your code.)
     
  7. Unread #4 - Feb 9, 2008 at 10:11 PM
  8. hockeykid09
    Joined:
    Mar 16, 2007
    Posts:
    1,162
    Referrals:
    0
    Sythe Gold:
    0

    hockeykid09 Guru
    Banned

    Need Help? Visual Basic Help Here!

    Lol if you want people to take you seriously take your gay sig out.
     
  9. Unread #5 - Feb 9, 2008 at 11:12 PM
  10. Swan
    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner

    Swan When They Cry...
    Retired Global Moderator

    Need Help? Visual Basic Help Here!

    Teh pwntz.

    I can make copypasta too.
     
  11. Unread #6 - Feb 11, 2008 at 7:33 PM
  12. demonavenger
    Joined:
    Feb 25, 2007
    Posts:
    536
    Referrals:
    0
    Sythe Gold:
    0

    demonavenger Forum Addict
    $5 USD Donor

    Need Help? Visual Basic Help Here!

    BOOOM! HEAD SHOT!!! So flamed :p
     
  13. Unread #7 - Feb 11, 2008 at 7:39 PM
  14. Line
    Joined:
    Jan 20, 2008
    Posts:
    271
    Referrals:
    1
    Sythe Gold:
    5

    Line Forum Addict

    Need Help? Visual Basic Help Here!

    Good job on the c/p...
     
< c++ code for sending emails | HD-DVD or Blue Ray - what is the better? >

Users viewing this thread
1 guest


 
 
Adblock breaks this site