A few simple questions. :)

Discussion in 'Programming General' started by WoW Sucks, Nov 1, 2007.

A few simple questions. :)
  1. Unread #81 - Nov 18, 2007 at 11:36 AM
  2. Nullware
    Joined:
    Jan 30, 2007
    Posts:
    1,761
    Referrals:
    4
    Sythe Gold:
    0

    Nullware Guru

    A few simple questions. :)

    I made this in a few minutes so it's not perfect but it works and I think it will be a good start for you. Hope it helps.:)
    Code:
    'Where "Source" is your target string and "WordNumber" is the word you want to find
    Private Function FindWord(Source As String, WordNumber As Integer) As Variant
    Dim NewString() As String
    
    'Strips one letter words from the source
    For i = 2 To Len(Source)
    If Mid(Source, i - 1, 1) = " " And Mid(Source, i + 1, 1) = " " Then
    Source = Mid(Source, 1, i - 2) & " " & Mid(Source, i + 2, Len(Source))
    End If
    Next i
    
    'Splits the modified source into words
    NewString() = Split(Source, " ")
    
    'Function returns the word you specified
    FindWord = NewString(WordNumber - 1)
    End Function
    Example Usage:
    Code:
    Private Sub Command1_Click()
    'Find the second word in the string from the textbox "Text1"
    MsgBox (FindWord(Text1.Text, 2))
    End Sub
    
     
  3. Unread #82 - Nov 23, 2007 at 11:42 AM
  4. WoW Sucks
    Joined:
    Jan 21, 2007
    Posts:
    3,708
    Referrals:
    3
    Sythe Gold:
    0

    WoW Sucks Global Moderator
    Banned

    A few simple questions. :)

    Thanks @ Nullware :)

    Right im back and ill try to get going with programming again.

    New question added.
     
  5. Unread #83 - Nov 23, 2007 at 8:26 PM
  6. jdsfighter
    Joined:
    Jan 21, 2007
    Posts:
    603
    Referrals:
    0
    Sythe Gold:
    0

    jdsfighter Forum Addict
    Visual Basic Programmers

    A few simple questions. :)

    On your newest question.
    Thats pretty easy, look in to the Command Button methods, try both the MouseDown and Click methods to see if they work for you.
     
  7. Unread #84 - Nov 23, 2007 at 10:44 PM
  8. Nullware
    Joined:
    Jan 30, 2007
    Posts:
    1,761
    Referrals:
    4
    Sythe Gold:
    0

    Nullware Guru

    A few simple questions. :)

    Well, here's what I thought you wanted for Question 25.

    Have 2 buttons named "Command1" and "Command2". Clicking on either button will tell you whether or not it was "Command1" that was clicked on.

    Code:
    Private Sub Command1_Click()
    MsgBox ("Clicked on Command1: " & Me.Command1)
    End Sub
    
    Private Sub Command2_Click()
    MsgBox ("Clicked on Command1: " & Me.Command1)
    End Sub
     
  9. Unread #85 - Dec 1, 2007 at 1:00 PM
  10. WoW Sucks
    Joined:
    Jan 21, 2007
    Posts:
    3,708
    Referrals:
    3
    Sythe Gold:
    0

    WoW Sucks Global Moderator
    Banned

    A few simple questions. :)

    Bump. New question added.
     
  11. Unread #86 - Dec 1, 2007 at 2:13 PM
  12. 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

    A few simple questions. :)

    Code:
    Private Sub Command1_Click()
        Dim numb As String, b As Long
        numb = "12145677777723232323234"
        Text1.Text = Empty
        b = 1
        While b <> Len(numb)
        MsgBox b
            Text1.Text = Text1.Text & Mid(numb, b, 1) & ","
            b = b + 1
        Wend
    End Sub
     
  13. Unread #87 - Dec 3, 2007 at 3:31 PM
  14. WoW Sucks
    Joined:
    Jan 21, 2007
    Posts:
    3,708
    Referrals:
    3
    Sythe Gold:
    0

    WoW Sucks Global Moderator
    Banned

    A few simple questions. :)

    Thanks covey =)

    New questoon added.
     
  15. Unread #88 - Dec 4, 2007 at 4:30 AM
  16. 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

    A few simple questions. :)

    Ok this first function just simply returns the contents of a file.
    To use:
    Code:
    Msgbox LoadFile(App.Path & "\afilehere.txt")
    The Function Code:
    Code:
    Public Function LoadFile(ByVal strPath As String) As String
        Dim lngFileNum As Long
        lngFileNum = FreeFile
        LoadFile = Empty
        Open strPath For Input As #lngFileNum
            LoadFile = Input(LOF(lngFileNum), lngFileNum)
        Close #lngFileNum
    End Function
    This second function does the same thing, but trims off the unwanted extra line that Visual Basic adds to a file when you write to it.
    To use:
    Code:
    Msgbox LoadFile(App.Path & "\afilehere.txt")
    The Function Code:
    Code:
    Public Function LoadFile(ByVal strPath As String) As String
        Dim lngFileNum As Long, strTemp As String, strLine() As String, i As Long
        lngFileNum = FreeFile
        LoadFile = Empty
        Open strPath For Input As #lngFileNum
            strTemp = Input(LOF(lngFileNum), lngFileNum)
        Close #lngFileNum
        strLine() = Split(strTemp, vbNewLine)
        For i = 0 To UBound(strLine())
            If i <> UBound(strLine()) Then
                If Trim(LoadFile) = Empty Then
                    LoadFile = strLine(i)
                Else
                    LoadFile = LoadFile & vbCrLf & strLine(i)
                End If
            End If
        Next i
    End Function
    Also you might want to add some error handling if the file doesn't exist, because otherwise the function will generate an error.
     
  17. Unread #89 - Dec 4, 2007 at 8:38 AM
  18. Nullware
    Joined:
    Jan 30, 2007
    Posts:
    1,761
    Referrals:
    4
    Sythe Gold:
    0

    Nullware Guru

    A few simple questions. :)

    Covey, he wanted to know if he could load a text file's contents into a Variant rather than a String. What I tried kept giving me errors so maybe I'll look into it later.
     
  19. Unread #90 - Dec 4, 2007 at 10:36 AM
  20. 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

    A few simple questions. :)

    this works fine....
    Code:
    Private Sub Command1_Click()
        Dim lol As Variant
        lol = LoadFile(PATH_HERE)
        MsgBox lol
    End Sub
     
  21. Unread #91 - Dec 4, 2007 at 10:57 AM
  22. Nullware
    Joined:
    Jan 30, 2007
    Posts:
    1,761
    Referrals:
    4
    Sythe Gold:
    0

    Nullware Guru

    A few simple questions. :)

    Oh ok, didn't know what you had would be directly compatible putting it into a Variant. Whatever I was trying kept giving some errors, so nice work.
     
  23. Unread #92 - Dec 4, 2007 at 1:11 PM
  24. 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

    A few simple questions. :)

    do you even know what a variant is?
    im pretty sure everything goes into a variant, as it..."varies"...
     
  25. Unread #93 - Dec 4, 2007 at 1:18 PM
  26. WoW Sucks
    Joined:
    Jan 21, 2007
    Posts:
    3,708
    Referrals:
    3
    Sythe Gold:
    0

    WoW Sucks Global Moderator
    Banned

    A few simple questions. :)

    Ok, that works thanks covey, so far i have this and it won't work. =/

    Code:
    Private Sub Command1_Click()
        Dim file As String
        file = LoadFile(App.Path & "\hello.txt")
        
        If InStr(1, hello, file) Then
            Picture1.Print file
        Else: MsgBox file
        
        End If
        
    End Sub
    
    Public Function LoadFile(ByVal strPath As String) As String
        Dim ff As Long
        ff = FreeFile
        LoadFile = Empty
        Open strPath For Input As #ff
            LoadFile = Input(LOF(ff), ff)
        Close #ff
    End Function
    
    I want it to look in the variant and see if there is a certain string/character there.

    Thanks


    EDIT: Also, what does the LOF but do/mean? thanks.
     
  27. Unread #94 - Dec 4, 2007 at 1:50 PM
  28. Nullware
    Joined:
    Jan 30, 2007
    Posts:
    1,761
    Referrals:
    4
    Sythe Gold:
    0

    Nullware Guru

    A few simple questions. :)

    Of course I know what a variant is. -.-
    Yes, I know that it's supposed to be compatible with all types but I was getting errors yesterday.. It doesn't matter because I can't even reproduce it now.

    Only a small error was stopping you. You inverted the two strings in your call to the InStr function, the string to search in goes first. You can also remove the "1," if you like as it starts searching at the beginning of the string by default.
    Code:
        If InStr(file, hello) Then
            Picture1.Print file
        Else: MsgBox file
        
        End If
    
    LOF(FileNumber) returns the size of the file in bytes of the file number that is passed through as an argument. Although, I didn't see it anywhere I'm guessing LOF stands for Length Of File.
     
  29. Unread #95 - Dec 4, 2007 at 2:26 PM
  30. WoW Sucks
    Joined:
    Jan 21, 2007
    Posts:
    3,708
    Referrals:
    3
    Sythe Gold:
    0

    WoW Sucks Global Moderator
    Banned

    A few simple questions. :)

    Great!

    Thanks alot =D
     
  31. Unread #96 - Dec 30, 2007 at 7:38 AM
  32. WoW Sucks
    Joined:
    Jan 21, 2007
    Posts:
    3,708
    Referrals:
    3
    Sythe Gold:
    0

    WoW Sucks Global Moderator
    Banned

    A few simple questions. :)

    New question added.

    I need this answer ASAP. Thanks.
     
  33. Unread #97 - Dec 30, 2007 at 9:18 AM
  34. Jazz00006
    Joined:
    Aug 26, 2005
    Posts:
    807
    Referrals:
    0
    Sythe Gold:
    0

    Jazz00006 Apprentice
    Visual Basic Programmers

    A few simple questions. :)

  35. Unread #98 - Dec 30, 2007 at 9:42 AM
  36. WoW Sucks
    Joined:
    Jan 21, 2007
    Posts:
    3,708
    Referrals:
    3
    Sythe Gold:
    0

    WoW Sucks Global Moderator
    Banned

    A few simple questions. :)

    Hmm im not sure its what i need.

    Each button has a number on it, and i need it to loop the amount of times which is on the caption.

    For example, the caption says 4 on it, so i want it to loop 4 times.
     
  37. Unread #99 - Dec 30, 2007 at 4:11 PM
  38. Nullware
    Joined:
    Jan 30, 2007
    Posts:
    1,761
    Referrals:
    4
    Sythe Gold:
    0

    Nullware Guru

    A few simple questions. :)

    Have a button called command1 and a textbot called text1 and use the following.

    Code:
    Private Sub Command1_Click()
    Limit = Command1.Caption
    For i = 1 To Limit
    Text1.Text = Text1 + 1
    Next i
    End Sub
    
    Fairly certain that's what you want. You can always clarify next time you catch me on MSN. :)
     
  39. Unread #100 - Dec 31, 2007 at 3:38 AM
  40. 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

    A few simple questions. :)

    I'm sorta confused with the question / what you're trying to do.
    But i think this is close to what you're after:
    Code:
    Private Sub Cap_Click(Index As Integer)
        Dim i As Long
        For i = Index To Cap.Count
            If Val(Cap(i).Caption) <= 0 Then
                Exit For
            End If
            Cap(i).Caption = Val(Cap(i).Caption + 1)
        Next i
    End Sub
    What that does is, It adds 1 to every button's caption including the button you clicked.
     
< echo in C | Need tutor on Programming >

Users viewing this thread
1 guest


 
 
Adblock breaks this site