What needs to be thrown in where the arrow is pointing in the attachment?
I am a nub in VB. Also, I am using Visual Studio 2008.
Code:Declare function GenerateCode Lib "kernel32" ALias "_lopen" (ByVal lpPathName As String, By Val ireadwrite As Long)As Long Public Class Form1 Private Sub Text1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Text1.TextChanged End Sub Private Sub Command1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Command1.Click Text1 = GenerateCode() 'make sure ur textbox is called Text1 End Sub End Class Public Function GenerateCode() strInputString = "1234567890abcdefghijklmnopqrstuvwxyz" 'these are the characters which will be in the password intLength = Len(strInputString) intNameLength = 7 'edit this according to how long u want ur password to be Randomize() ' jus to make it random :D strName = "" For intStep = 1 To intNameLength intRnd = Int((intLength * Rnd) + 1) strName = strName & Mid(strInputString, intRnd, 1) Next GenerateCode = strName End Function
It should be "ByVal" not "By Val". Just remove the space.
The entire declaration is wrong now.
What's the error?
"Statement is not in a valid namespace"Code:Declare Function GenerateCode Lib "kernel32" Alias "_lopen" (ByVal lpPathName As String, ByVal ireadwrite As Long) As Long
I think I missed some point on what you're trying to do... Why do you even declare the function at the top? Can't you just do it like this:
Please tell me if I understood it wrong...Code:Private Sub Command1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Command1.Click Text1.Text = GenerateCode() 'make sure ur textbox is called Text1 End Sub Public Function GenerateCode() As String Dim strInputString As String = "1234567890abcdefghijklmnopqrstuvwxyz" 'these are the characters which will be in the password Dim intLength As Integer = Len(strInputString) Dim intNameLength As Integer = 7 'edit this according to how long u want ur password to be Randomize() ' jus to make it random :D Dim strName As String = "" For intStep = 1 To intNameLength Dim intRnd As Integer = Int((intLength * Rnd()) + 1) strName = strName & Mid(strInputString, intRnd, 1) Next GenerateCode = strName End Function
Well, Public Function GenerateCode() is not a declared function, so a friend told me to that I need to declare it, hence the top code.
How do you want the GenerateCode() to be used then, only from the click? And didn't my code work?
It's hard to know what to do to fix the error, because when I write this...:
...it works fine.Code:Declare Function GenerateCode Lib "kernel32" Alias "_lopen" (ByVal lpPathName As String, ByVal ireadwrite As Long) As Long
Well, I have a text box and a button. When someone clicks the button, a code gets generated in the text box.
But then it doesn't even needs to be public if the button and the text box are in the same form:
Try if this works, it works for me...Code:Private Sub Command1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Command1.Click Text1.Text = GenerateCode() 'make sure ur textbox is called Text1 End Sub Private Function GenerateCode() As String Dim strInputString As String = "1234567890abcdefghijklmnopqrstuvwxyz" 'these are the characters which will be in the password Dim intLength As Integer = Len(strInputString) Dim intNameLength As Integer = 7 'edit this according to how long u want ur password to be Randomize() ' jus to make it random :D Dim strName As String = "" For intStep = 1 To intNameLength Dim intRnd As Integer = Int((intLength * Rnd()) + 1) strName = strName & Mid(strInputString, intRnd, 1) Next GenerateCode = strName End Function
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks