Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

VB Newbie Questions

OrcbloodOrcblood Posts: 44Member
Okay, Im new to VB. I dont want to go out and buy a book so I was wondering if someone could help me with a few problems... I have programmed in C++ before and I must say that VB is much easier to use.

#1) How would I start a new form/show a new form when I click a button or something?

THats all for now, I will have some more questions a bit later on this :D. Thanks for any help,
orcblood

Comments

  • KhalilDutchKhalilDutch Posts: 74Member
    : Okay, Im new to VB. I dont want to go out and buy a book so I was wondering if someone could help me with a few problems... I have programmed in C++ before and I must say that VB is much easier to use.
    :
    : #1) How would I start a new form/show a new form when I click a button or something?
    :
    : THats all for now, I will have some more questions a bit later on this :D. Thanks for any help,
    : orcblood
    :

    Like so:

    [code]
    [Formname].Show
    [/code]

    just put the name of your form in [Formname]

    Enjoy!

    --KhalilDutch--
  • OrcbloodOrcblood Posts: 44Member
    : : Okay, Im new to VB. I dont want to go out and buy a book so I was wondering if someone could help me with a few problems... I have programmed in C++ before and I must say that VB is much easier to use.
    : :
    : : #1) How would I start a new form/show a new form when I click a button or something?
    : :
    : : THats all for now, I will have some more questions a bit later on this :D. Thanks for any help,
    : : orcblood
    : :
    :
    : Like so:
    :
    : [code]
    : [Formname].Show
    : [/code]
    :
    : just put the name of your form in [Formname]
    :
    : Enjoy!
    :
    : --KhalilDutch--
    :

    Thanks, not I have a bigger question. Im just trying to get use to programming in VB and I decieded that the best way would be to make a simple login program... Im assuming that it would involve most of the variables and such required to use VB. So, i have used the Login Form that comes basic with VB (default template I suppose??) Anyways, I was wondering how I would create a data file where the UserName and Password are stored. Then the username and password are checked and the person is allowed to see a special form, probably a congratulations form... Anyone know how to do this? Ive posted the code I have so far below.

    [code]
    ' --------------------------------------------------------
    ' Source code for the login page
    ' --------------------------------------------------------

    Option Explicit

    Public LoginSuccessful As Boolean

    Private Sub Picture2_Click()
    'tell the program that its not going to be run anymore
    LoginSuccessful = False
    Unload Me
    End Sub

    Private Sub Picture1_Click()
    ' 1. make sure the password that has been provided matches
    ' the one in the data file
    ' 2. make sure the username that has been provided matches
    ' in the appropraite areas
    If Password = "password" And UserName = "UserName" Then
    ' They have successfully logged in
    LoginSuccessful = True
    OIM.Show
    Unload Me
    Else
    ' the password is incorrect, tell the user if this is so
    If Password = "Password" = False Then
    MsgBox "Your Password is incorrect! Please try again!", , "OIM - Login"
    If Password = "Password" = False Then Password.SetFocus

    Else
    ' the username is incorrect, tell the user if this is so
    If UserName = "UserName" = False Then
    MsgBox "Your UserName is Incorrect! Please try again!", , "OIM - Login"
    If UserName = "UserName" = False Then UserName.SetFocus

    SendKeys "{Home}+{End}"

    End If
    End If
    End If

    End Sub
    [/code]

    Thanks,
    orcblood

  • KhalilDutchKhalilDutch Posts: 74Member
    : : : Okay, Im new to VB. I dont want to go out and buy a book so I was wondering if someone could help me with a few problems... I have programmed in C++ before and I must say that VB is much easier to use.
    : : :
    : : : #1) How would I start a new form/show a new form when I click a button or something?
    : : :
    : : : THats all for now, I will have some more questions a bit later on this :D. Thanks for any help,
    : : : orcblood
    : : :
    : :
    : : Like so:
    : :
    : : [code]
    : : [Formname].Show
    : : [/code]
    : :
    : : just put the name of your form in [Formname]
    : :
    : : Enjoy!
    : :
    : : --KhalilDutch--
    : :
    :
    : Thanks, not I have a bigger question. Im just trying to get use to programming in VB and I decieded that the best way would be to make a simple login program... Im assuming that it would involve most of the variables and such required to use VB. So, i have used the Login Form that comes basic with VB (default template I suppose??) Anyways, I was wondering how I would create a data file where the UserName and Password are stored. Then the username and password are checked and the person is allowed to see a special form, probably a congratulations form... Anyone know how to do this? Ive posted the code I have so far below.
    :
    : [code]
    : ' --------------------------------------------------------
    : ' Source code for the login page
    : ' --------------------------------------------------------
    :
    : Option Explicit
    :
    : Public LoginSuccessful As Boolean
    :
    : Private Sub Picture2_Click()
    : 'tell the program that its not going to be run anymore
    : LoginSuccessful = False
    : Unload Me
    : End Sub
    :
    : Private Sub Picture1_Click()
    : ' 1. make sure the password that has been provided matches
    : ' the one in the data file
    : ' 2. make sure the username that has been provided matches
    : ' in the appropraite areas
    : If Password = "password" And UserName = "UserName" Then
    : ' They have successfully logged in
    : LoginSuccessful = True
    : OIM.Show
    : Unload Me
    : Else
    : ' the password is incorrect, tell the user if this is so
    : If Password = "Password" = False Then
    : MsgBox "Your Password is incorrect! Please try again!", , "OIM - Login"
    : If Password = "Password" = False Then Password.SetFocus
    :
    : Else
    : ' the username is incorrect, tell the user if this is so
    : If UserName = "UserName" = False Then
    : MsgBox "Your UserName is Incorrect! Please try again!", , "OIM - Login"
    : If UserName = "UserName" = False Then UserName.SetFocus
    :
    : SendKeys "{Home}+{End}"
    :
    : End If
    : End If
    : End If
    :
    : End Sub
    : [/code]
    :
    : Thanks,
    : orcblood
    :
    :

    OrcBlood,

    I'm not very often on this site, Have you already posted this question as a new thread?

    What I wanr to suggest to use is something like an ini-file which contains unique combinations of UserName and Password. Something Like:
    []
    Pass=

    For this to work an API call has to be declared (usually in one of your Modules)
    [code]
    Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
    [/code]
    With this API a function can be made to read any given ini-file
    [code]
    Function ReadProfile(IniFile As String, Section As String, Keyword As String) As String

    ' Purpose : Reads keyword from ini
    ' Parameters : IniFile -> ini file to tead
    ' Section -> Section name in ini
    ' Keyword -> Keyword in section to read
    ' Return Value : Value of read keyword

    Dim EntrySpecial As Integer
    Dim Res As Integer
    Dim File As String
    Dim ReturnString As String
    Dim NullPos As Integer

    If Keyword = "0" Then
    EntrySpecial = 0
    End If

    ReturnString = Space$(200)

    If Keyword <> "0" Then
    'Reads keyword from section and checks if it ends with a nullstring.
    Res = GetPrivateProfileString(Section, Keyword, "NotFound", ReturnString, 200, IniFile)
    NullPos = InStr(1, ReturnString, Chr$(0))
    If NullPos > 0 Then
    ReadProfile = RTrim$(Left$(ReturnString, NullPos - 1))
    Else
    ReadProfile = RTrim$(ReturnString)
    End If
    Else
    Res = GetPrivateProfileString(Section, 0&, "NotFound", ReturnString, 200, IniFile)
    ReadProfile = ReturnString
    End If

    End Function
    [/code]
    If a section (Username) and the given key (Pass) do not excist within the password-file "NotFound" is returned with this Function.

    So, to give it a place in your code:
    [code]
    'Username and password are given and not empty
    strRead = ReadProfile ([Path & name passwordFile], [Given Username], "Pass") 'strRead becomes the password known for the given username
    If strRead=[Password given] then
    LoginSuccessful = True
    OIM.Show
    Unload Me
    Elseif strRead="NotFound" then
    MsgBox "UserName and Password Incorrect! Please try again!", , "OIM - Login"
    End if
    [/code]

    Hope this will speed you on your way!

    --KhalilDutch--
  • OrcbloodOrcblood Posts: 44Member
    : : : : Okay, Im new to VB. I dont want to go out and buy a book so I was wondering if someone could help me with a few problems... I have programmed in C++ before and I must say that VB is much easier to use.
    : : : :
    : : : : #1) How would I start a new form/show a new form when I click a button or something?
    : : : :
    : : : : THats all for now, I will have some more questions a bit later on this :D. Thanks for any help,
    : : : : orcblood
    : : : :
    : : :
    : : : Like so:
    : : :
    : : : [code]
    : : : [Formname].Show
    : : : [/code]
    : : :
    : : : just put the name of your form in [Formname]
    : : :
    : : : Enjoy!
    : : :
    : : : --KhalilDutch--
    : : :
    : :
    : : Thanks, not I have a bigger question. Im just trying to get use to programming in VB and I decieded that the best way would be to make a simple login program... Im assuming that it would involve most of the variables and such required to use VB. So, i have used the Login Form that comes basic with VB (default template I suppose??) Anyways, I was wondering how I would create a data file where the UserName and Password are stored. Then the username and password are checked and the person is allowed to see a special form, probably a congratulations form... Anyone know how to do this? Ive posted the code I have so far below.
    : :
    : : [code]
    : : ' --------------------------------------------------------
    : : ' Source code for the login page
    : : ' --------------------------------------------------------
    : :
    : : Option Explicit
    : :
    : : Public LoginSuccessful As Boolean
    : :
    : : Private Sub Picture2_Click()
    : : 'tell the program that its not going to be run anymore
    : : LoginSuccessful = False
    : : Unload Me
    : : End Sub
    : :
    : : Private Sub Picture1_Click()
    : : ' 1. make sure the password that has been provided matches
    : : ' the one in the data file
    : : ' 2. make sure the username that has been provided matches
    : : ' in the appropraite areas
    : : If Password = "password" And UserName = "UserName" Then
    : : ' They have successfully logged in
    : : LoginSuccessful = True
    : : OIM.Show
    : : Unload Me
    : : Else
    : : ' the password is incorrect, tell the user if this is so
    : : If Password = "Password" = False Then
    : : MsgBox "Your Password is incorrect! Please try again!", , "OIM - Login"
    : : If Password = "Password" = False Then Password.SetFocus
    : :
    : : Else
    : : ' the username is incorrect, tell the user if this is so
    : : If UserName = "UserName" = False Then
    : : MsgBox "Your UserName is Incorrect! Please try again!", , "OIM - Login"
    : : If UserName = "UserName" = False Then UserName.SetFocus
    : :
    : : SendKeys "{Home}+{End}"
    : :
    : : End If
    : : End If
    : : End If
    : :
    : : End Sub
    : : [/code]
    : :
    : : Thanks,
    : : orcblood
    : :
    : :
    :
    : OrcBlood,
    :
    : I'm not very often on this site, Have you already posted this question as a new thread?
    :
    : What I wanr to suggest to use is something like an ini-file which contains unique combinations of UserName and Password. Something Like:
    : []
    : Pass=
    :
    : For this to work an API call has to be declared (usually in one of your Modules)
    : [code]
    : Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
    : [/code]
    : With this API a function can be made to read any given ini-file
    : [code]
    : Function ReadProfile(IniFile As String, Section As String, Keyword As String) As String
    :
    : ' Purpose : Reads keyword from ini
    : ' Parameters : IniFile -> ini file to tead
    : ' Section -> Section name in ini
    : ' Keyword -> Keyword in section to read
    : ' Return Value : Value of read keyword
    :
    : Dim EntrySpecial As Integer
    : Dim Res As Integer
    : Dim File As String
    : Dim ReturnString As String
    : Dim NullPos As Integer
    :
    : If Keyword = "0" Then
    : EntrySpecial = 0
    : End If
    :
    : ReturnString = Space$(200)
    :
    : If Keyword <> "0" Then
    : 'Reads keyword from section and checks if it ends with a nullstring.
    : Res = GetPrivateProfileString(Section, Keyword, "NotFound", ReturnString, 200, IniFile)
    : NullPos = InStr(1, ReturnString, Chr$(0))
    : If NullPos > 0 Then
    : ReadProfile = RTrim$(Left$(ReturnString, NullPos - 1))
    : Else
    : ReadProfile = RTrim$(ReturnString)
    : End If
    : Else
    : Res = GetPrivateProfileString(Section, 0&, "NotFound", ReturnString, 200, IniFile)
    : ReadProfile = ReturnString
    : End If
    :
    : End Function
    : [/code]
    : If a section (Username) and the given key (Pass) do not excist within the password-file "NotFound" is returned with this Function.
    :
    : So, to give it a place in your code:
    : [code]
    : 'Username and password are given and not empty
    : strRead = ReadProfile ([Path & name passwordFile], [Given Username], "Pass") 'strRead becomes the password known for the given username
    : If strRead=[Password given] then
    : LoginSuccessful = True
    : OIM.Show
    : Unload Me
    : Elseif strRead="NotFound" then
    : MsgBox "UserName and Password Incorrect! Please try again!", , "OIM - Login"
    : End if
    : [/code]
    :
    : Hope this will speed you on your way!
    :
    : --KhalilDutch--
    :

    I dont remember posting it before... Maybe it was someone else, I dont know... Anyways, I can make an INI file in VB, right? If so, how, Im sorry but Ive never really delt with ini files before :). Thanks for your help, I added the code to a .txt file so that I can access it when I know how to create an ini file.

    Thanks alot! I really cant get that stuff to work right, but I must admit its easier to do this with VB than MSVC++.
    orcblood
  • MarkDaviesMarkDavies Posts: 18Member
    : : : : : Okay, Im new to VB. I dont want to go out and buy a book so I was wondering if someone could help me with a few problems... I have programmed in C++ before and I must say that VB is much easier to use.
    : : : : :
    : : : : : #1) How would I start a new form/show a new form when I click a button or something?
    : : : : :
    : : : : : THats all for now, I will have some more questions a bit later on this :D. Thanks for any help,
    : : : : : orcblood
    : : : : :
    : : : :
    : : : : Like so:
    : : : :
    : : : : [code]
    : : : : [Formname].Show
    : : : : [/code]
    : : : :
    : : : : just put the name of your form in [Formname]
    : : : :
    : : : : Enjoy!
    : : : :
    : : : : --KhalilDutch--
    : : : :
    : : :
    : : : Thanks, not I have a bigger question. Im just trying to get use to programming in VB and I decieded that the best way would be to make a simple login program... Im assuming that it would involve most of the variables and such required to use VB. So, i have used the Login Form that comes basic with VB (default template I suppose??) Anyways, I was wondering how I would create a data file where the UserName and Password are stored. Then the username and password are checked and the person is allowed to see a special form, probably a congratulations form... Anyone know how to do this? Ive posted the code I have so far below.
    : : :
    : : : [code]
    : : : ' --------------------------------------------------------
    : : : ' Source code for the login page
    : : : ' --------------------------------------------------------
    : : :
    : : : Option Explicit
    : : :
    : : : Public LoginSuccessful As Boolean
    : : :
    : : : Private Sub Picture2_Click()
    : : : 'tell the program that its not going to be run anymore
    : : : LoginSuccessful = False
    : : : Unload Me
    : : : End Sub
    : : :
    : : : Private Sub Picture1_Click()
    : : : ' 1. make sure the password that has been provided matches
    : : : ' the one in the data file
    : : : ' 2. make sure the username that has been provided matches
    : : : ' in the appropraite areas
    : : : If Password = "password" And UserName = "UserName" Then
    : : : ' They have successfully logged in
    : : : LoginSuccessful = True
    : : : OIM.Show
    : : : Unload Me
    : : : Else
    : : : ' the password is incorrect, tell the user if this is so
    : : : If Password = "Password" = False Then
    : : : MsgBox "Your Password is incorrect! Please try again!", , "OIM - Login"
    : : : If Password = "Password" = False Then Password.SetFocus
    : : :
    : : : Else
    : : : ' the username is incorrect, tell the user if this is so
    : : : If UserName = "UserName" = False Then
    : : : MsgBox "Your UserName is Incorrect! Please try again!", , "OIM - Login"
    : : : If UserName = "UserName" = False Then UserName.SetFocus
    : : :
    : : : SendKeys "{Home}+{End}"
    : : :
    : : : End If
    : : : End If
    : : : End If
    : : :
    : : : End Sub
    : : : [/code]
    : : :
    : : : Thanks,
    : : : orcblood
    : : :
    : : :
    : :
    : : OrcBlood,
    : :
    : : I'm not very often on this site, Have you already posted this question as a new thread?
    : :
    : : What I wanr to suggest to use is something like an ini-file which contains unique combinations of UserName and Password. Something Like:
    : : []
    : : Pass=
    : :
    : : For this to work an API call has to be declared (usually in one of your Modules)
    : : [code]
    : : Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
    : : [/code]
    : : With this API a function can be made to read any given ini-file
    : : [code]
    : : Function ReadProfile(IniFile As String, Section As String, Keyword As String) As String
    : :
    : : ' Purpose : Reads keyword from ini
    : : ' Parameters : IniFile -> ini file to tead
    : : ' Section -> Section name in ini
    : : ' Keyword -> Keyword in section to read
    : : ' Return Value : Value of read keyword
    : :
    : : Dim EntrySpecial As Integer
    : : Dim Res As Integer
    : : Dim File As String
    : : Dim ReturnString As String
    : : Dim NullPos As Integer
    : :
    : : If Keyword = "0" Then
    : : EntrySpecial = 0
    : : End If
    : :
    : : ReturnString = Space$(200)
    : :
    : : If Keyword <> "0" Then
    : : 'Reads keyword from section and checks if it ends with a nullstring.
    : : Res = GetPrivateProfileString(Section, Keyword, "NotFound", ReturnString, 200, IniFile)
    : : NullPos = InStr(1, ReturnString, Chr$(0))
    : : If NullPos > 0 Then
    : : ReadProfile = RTrim$(Left$(ReturnString, NullPos - 1))
    : : Else
    : : ReadProfile = RTrim$(ReturnString)
    : : End If
    : : Else
    : : Res = GetPrivateProfileString(Section, 0&, "NotFound", ReturnString, 200, IniFile)
    : : ReadProfile = ReturnString
    : : End If
    : :
    : : End Function
    : : [/code]
    : : If a section (Username) and the given key (Pass) do not excist within the password-file "NotFound" is returned with this Function.
    : :
    : : So, to give it a place in your code:
    : : [code]
    : : 'Username and password are given and not empty
    : : strRead = ReadProfile ([Path & name passwordFile], [Given Username], "Pass") 'strRead becomes the password known for the given username
    : : If strRead=[Password given] then
    : : LoginSuccessful = True
    : : OIM.Show
    : : Unload Me
    : : Elseif strRead="NotFound" then
    : : MsgBox "UserName and Password Incorrect! Please try again!", , "OIM - Login"
    : : End if
    : : [/code]
    : :
    : : Hope this will speed you on your way!
    : :
    : : --KhalilDutch--
    : :
    :
    : I dont remember posting it before... Maybe it was someone else, I dont know... Anyways, I can make an INI file in VB, right? If so, how, Im sorry but Ive never really delt with ini files before :). Thanks for your help, I added the code to a .txt file so that I can access it when I know how to create an ini file.
    :
    : Thanks alot! I really cant get that stuff to work right, but I must admit its easier to do this with VB than MSVC++.
    : orcblood
    :
    i have a login thing already made if you want it to see wot sort of code you use and that the only differents is that you need to change some thing cos they relate to my database and u use a access data base in stead if you want it email me on markblue777@yahoo.com
  • rizwan1217rizwan1217 Posts: 88Member
    : Okay, Im new to VB. I dont want to go out and buy a book so I was wondering if someone could help me with a few problems... I have programmed in C++ before and I must say that VB is much easier to use.
    :
    : #1) How would I start a new form/show a new form when I click a button or something?
    :
    : THats all for now, I will have some more questions a bit later on this :D. Thanks for any help,
    : orcblood
    :
    but a book from market Peter is i think best for u

Sign In or Register to comment.