VBA

Moderators: PavlinII
Number of threads: 1673
Number of posts: 3078

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
VB Newbie Questions Posted by Orcblood on 7 Mar 2003 at 3:22 PM
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
Report
Re: VB Newbie Questions Posted by KhalilDutch on 12 Mar 2003 at 1:31 AM
: 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:

[Formname].Show


just put the name of your form in [Formname]

Enjoy!

--KhalilDutch--
Report
Re: VB Newbie Questions Posted by Orcblood on 12 Mar 2003 at 8:22 AM
: : 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:
:
:
: [Formname].Show
: 

:
: 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.

' --------------------------------------------------------
' 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


Thanks,
orcblood

Report
Re: VB Newbie Questions Posted by KhalilDutch on 19 Mar 2003 at 9:03 AM
: : : 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:
: :
: :
: : [Formname].Show
: : 

: :
: : 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.
:
:
: ' --------------------------------------------------------
: ' 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
: 

:
: 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:
[<UserName>]
Pass=<PassWord>

For this to work an API call has to be declared (usually in one of your Modules)
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

With this API a function can be made to read any given ini-file
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

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:
'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


Hope this will speed you on your way!

--KhalilDutch--
Report
Re: VB Newbie Questions Posted by Orcblood on 19 Mar 2003 at 1:48 PM
: : : : 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:
: : :
: : :
: : : [Formname].Show
: : : 

: : :
: : : 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.
: :
: :
: : ' --------------------------------------------------------
: : ' 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
: : 

: :
: : 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:
: [<UserName>]
: Pass=<PassWord>
:
: For this to work an API call has to be declared (usually in one of your Modules)
:
: 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
: 

: With this API a function can be made to read any given ini-file
:
: 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
: 

: 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:
:
: '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
: 

:
: 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
Report
Re: VB Newbie Questions Posted by MarkDavies on 20 Aug 2003 at 5:34 AM
: : : : : 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:
: : : :
: : : :
: : : : [Formname].Show
: : : : 

: : : :
: : : : 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.
: : :
: : :
: : : ' --------------------------------------------------------
: : : ' 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
: : : 

: : :
: : : 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:
: : [<UserName>]
: : Pass=<PassWord>
: :
: : For this to work an API call has to be declared (usually in one of your Modules)
: :
: : 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
: : 

: : With this API a function can be made to read any given ini-file
: :
: : 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
: : 

: : 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:
: :
: : '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
: : 

: :
: : 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
Report
Re: VB Newbie Questions Posted by rizwan1217 on 6 Oct 2003 at 9:37 PM
: 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




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.