• Log in or sign up for an account here: https://www.sythe.org/login

A few simple questions. :)

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
 
A few simple questions. :)
Thanks @ Nullware :)

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

New question added.
 
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.
 
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
 
A few simple questions. :)
Bump. New question added.
 
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
 
A few simple questions. :)
Thanks covey =)

New questoon added.
 
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.
 
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.
 
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.
 
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.
 
A few simple questions. :)
Covey said:
do you even know what a variant is?
im pretty sure everything goes into a variant, as it..."varies"...
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.

I want it to look in the variant and see if there is a certain string/character there.
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.
 
A few simple questions. :)
Great!

Thanks alot =D
 
A few simple questions. :)
New question added.

I need this answer ASAP. Thanks.
 
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.
 
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. :)
 
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.
 
Runescape Gamblingrunescape gambling
Back
Top