explanation of codes in Visual Basic when creating User form

Hi,
I am trying to create a user form in Visual Basic however I'm trying to 
teach myself by reading/watching tutorials. (www.contectures.o.ca, etc)
A lot of the instructions I am seeing simply give the code rather than 
explain how to actually write one from scratch.
So...
I need to know what each 'term' means so I can understand how the codes work.
Any help is much appreciated :)

One of the first codes is for the Add button
           Private Sub cmdAdd_Click()
           Dim iRow As Long
           Dim ws As Worksheet
           Set ws = Worksheets("PartsData")
What does each term refer to?
Dim
iRow
As Long
ws
Set

etc?

Is there a website that has all these definitions?
I don't really want to just copy and paste codes because when my form 
doesn't work I can't work out where the error is.

Thank you in advance.
Rachel
0
Rachel (30)
11/2/2009 1:35:01 AM
excel.newusers 15348 articles. 2 followers. Follow

2 Replies
910 Views

Similar Articles

[PageSpeed] 22

Depends on how extensive an explanation you need. A sketchy explantion of 
most of the terms is available in the help files within the Visual Basic 
editor. For example, looking up "Dim" will give you the syntax of Dim with 
its minimum and optional parts, and a few examples. In its simplest use Dim 
is used to define a variable. For the example you gave

    Dim iRow as Long

means you have defined a variable named "iRow" and you want it to be the 
data type long integer ("Long" in VB-speak). The named variable can then be 
used later within the function or subroutine. In general, you can name your 
variables almost anything you want but there are some restrictions -- you 
can't have a variable named as all integers for example (there's no way to 
tell that "1234" means your variable instead of just a number), and you 
cannot give a variable a name that is a reserved word in visual basic.

Following that pattern, the line:

    Dim ws as Worksheet

means you defined a variable named "ws" as a Worksheet. Defining that 
variable just reserves memory for its later use, and does not actually 
assign a value to it (more acurately, it has the special value of "Nothing" 
until you tell the subroutine which Worksheet you want the variable ws to 
refer to). Speaking of which....

    Set ws = Worksheets("PartsData")

means you have set the variable ws, which you previously defined as a 
variable referring to a Worksheet, to refer to the "PartsData" Worksheet. 
For that particular example, presumably the workbook actually has a 
Worksheet named "PartsData", otherwise any of the following code using the 
variable ws is going to get really confused.

If you have any background in programming -- and in particular 
object-oriented programming -- you can stumble your way through most Excel 
programming just by recording Macros and looking at the resulting code, 
supplmented with a healthy dose of the help files.

On the other hand, if you do not have any background at all in programming, 
or if all of that Visual Basic for applications code looks like double-talk, 
one of the many books on Excel programming might be advisable. The general 
observation is that object-orietned programming has a fairly steep leanring 
curve, because everything it talks about refers to something else you don't 
know about. In that case a good book that actually steps through examples 
and explains what is going on might be useful.

Regards,

"Rachel" <Rachel@discussions.microsoft.com> wrote in message 
news:653D7464-FCF3-47AF-A392-FDCA7B9EF709@microsoft.com...
> Hi,
> I am trying to create a user form in Visual Basic however I'm trying to
> teach myself by reading/watching tutorials. (www.contectures.o.ca, etc)
> A lot of the instructions I am seeing simply give the code rather than
> explain how to actually write one from scratch.
> So...
> I need to know what each 'term' means so I can understand how the codes 
> work.
> Any help is much appreciated :)
>
> One of the first codes is for the Add button
>           Private Sub cmdAdd_Click()
>           Dim iRow As Long
>           Dim ws As Worksheet
>           Set ws = Worksheets("PartsData")
> What does each term refer to?
> Dim
> iRow
> As Long
> ws
> Set
>
> etc?
>
> Is there a website that has all these definitions?
> I don't really want to just copy and paste codes because when my form
> doesn't work I can't work out where the error is.
>
> Thank you in advance.
> Rachel 

0
luken4d (4)
11/2/2009 6:32:57 AM
Thanks very much Sox,
I think I will invest in a good book and get studying.
Cheers


"Sox" wrote:

> Depends on how extensive an explanation you need. A sketchy explantion of 
> most of the terms is available in the help files within the Visual Basic 
> editor. For example, looking up "Dim" will give you the syntax of Dim with 
> its minimum and optional parts, and a few examples. In its simplest use Dim 
> is used to define a variable. For the example you gave
> 
>     Dim iRow as Long
> 
> means you have defined a variable named "iRow" and you want it to be the 
> data type long integer ("Long" in VB-speak). The named variable can then be 
> used later within the function or subroutine. In general, you can name your 
> variables almost anything you want but there are some restrictions -- you 
> can't have a variable named as all integers for example (there's no way to 
> tell that "1234" means your variable instead of just a number), and you 
> cannot give a variable a name that is a reserved word in visual basic.
> 
> Following that pattern, the line:
> 
>     Dim ws as Worksheet
> 
> means you defined a variable named "ws" as a Worksheet. Defining that 
> variable just reserves memory for its later use, and does not actually 
> assign a value to it (more acurately, it has the special value of "Nothing" 
> until you tell the subroutine which Worksheet you want the variable ws to 
> refer to). Speaking of which....
> 
>     Set ws = Worksheets("PartsData")
> 
> means you have set the variable ws, which you previously defined as a 
> variable referring to a Worksheet, to refer to the "PartsData" Worksheet. 
> For that particular example, presumably the workbook actually has a 
> Worksheet named "PartsData", otherwise any of the following code using the 
> variable ws is going to get really confused.
> 
> If you have any background in programming -- and in particular 
> object-oriented programming -- you can stumble your way through most Excel 
> programming just by recording Macros and looking at the resulting code, 
> supplmented with a healthy dose of the help files.
> 
> On the other hand, if you do not have any background at all in programming, 
> or if all of that Visual Basic for applications code looks like double-talk, 
> one of the many books on Excel programming might be advisable. The general 
> observation is that object-orietned programming has a fairly steep leanring 
> curve, because everything it talks about refers to something else you don't 
> know about. In that case a good book that actually steps through examples 
> and explains what is going on might be useful.
> 
> Regards,
> 
> "Rachel" <Rachel@discussions.microsoft.com> wrote in message 
> news:653D7464-FCF3-47AF-A392-FDCA7B9EF709@microsoft.com...
> > Hi,
> > I am trying to create a user form in Visual Basic however I'm trying to
> > teach myself by reading/watching tutorials. (www.contectures.o.ca, etc)
> > A lot of the instructions I am seeing simply give the code rather than
> > explain how to actually write one from scratch.
> > So...
> > I need to know what each 'term' means so I can understand how the codes 
> > work.
> > Any help is much appreciated :)
> >
> > One of the first codes is for the Add button
> >           Private Sub cmdAdd_Click()
> >           Dim iRow As Long
> >           Dim ws As Worksheet
> >           Set ws = Worksheets("PartsData")
> > What does each term refer to?
> > Dim
> > iRow
> > As Long
> > ws
> > Set
> >
> > etc?
> >
> > Is there a website that has all these definitions?
> > I don't really want to just copy and paste codes because when my form
> > doesn't work I can't work out where the error is.
> >
> > Thank you in advance.
> > Rachel 
> 
0
Rachel (30)
11/4/2009 11:19:02 PM
Reply:

Similar Artilces:

Problems with creating a newsletter
I chose the form "Newsletter - email". I have created a 3 page newsletter. Now, I have NO IDEA how to send it out as an email. I do not want to send it as an attachment. I cannot figure out which "save as" format or what I need to do so that i can email this newsletter. Is there a website that goes through how to do this? Am I correct when I say that it has to be html in order for me to send it as email? That is not one of the options. Any help you give me would be greatly appreciated. Thank you, Markis www.adreamforabetterworld.com ...

visual basic
Hi, I trying to retrieve values from a table to calculate the 14days average value of a stock closing price. However, i encounter some problem as stated beside the code as follows: Function DaysAvgs() 'Calculate the average value of a given value. Dim db As DAO.Database Dim rst As DAO.Recordset Dim varBookmark As Variant Dim numAve, numDaysAvg As Double Dim intA, intB, lngCount As Integer Set db = CurrentDb 'Open Table Set rst = db.OpenRecordset("SGX Individual Historical", dbOpenTable) rst.MoveFirst Do While Not rst.EOF intA = 1 intB = 0 varBookmark = rst.Bookmark n...

Removing multiple users from Outlook
We did some computer switching, which involved uninstalling a copy of Office XP and replacing it with a copy of Office 2003. Now when I open Outlook, it makes me choose a user. This wasn't in the .pst file which was transferred for the other computer, but apparenly it was on this computer someplace. How can I get Outlook to simply open for the one account without that dialog box popping up? Aloha Annie, Control Panel | Mail | Show Profiles...remove any profiles you don't want. Select the one you do want and set it as the default. (if there are more than one left) -Ben-...

code examples for BITS
Hi, I am looking for sample codes for programming background intelligent transfer service..I was able to see sample code in .NET, but I'm specifically looking for VC++ 6.0 (command-line application).Please help me.. Thanks, NKH ...

Access 2007 and Vista code problem
I am developing a database on a XP SP2 machine. On a form I have created some buttons with event procedures that run 2 queries and open a form. I sent the db to someone running Access 2007 on a Vista machine and nothing happens when she clicks the buttons and there are no messages. I know nothing about Vista so thanks in advance for any help. Tim Might be a reference problem, have them open the open a code window and click tools references. See what says missing and tell them what should be there, Add it and it should work. Duff "Tim Reid" <TimReid@discussions.micr...

Word2007. Checkbox. No Form
Hello! We have a document (not a form) that we would like to use checkboxes in. This document has a couple of sections where it would be useful if the user could check if something is applicable. We can't protect the whole document. Thank you for your help! Stacey I actually used this feature in a form this morning. Although you don't say what version of Word you are using, you can access the Control Toolbox toolbar in Word 2003, or in Word 2007, it is on Developer tab. To show the developer tab, click the Microsoft Office Button and then click Word Options. S...

VBA to creating autotext entries or quickparts in different catego
I have a VBA application that basically allows people to easily create autotext entiries, move them between machines and use them making comments on assignments. Currently it operates in EXACTLY the same way in Word 2003 and 2007 (using userforms) and I want to keep that as long as possible. You can see the application at http://emarking-assistant.baker-evans.com and either the screen image or the video demos will give you an idea of what I am doing Currently I store all the comments in a long list of autotext entries that is displayed in a field with the value of the entr...

Opening pub files created with older Publisher versions #2
I have just upgraded to Publisher 2003 from 2000 and am having trouble with pub files sent to me for our chuch newsletter which is using Publisher 97 The text is not wrapping around graphics boxes. Can I fix this? I really don't want to go back to Pub 200 Thank Richard this is caused by Publisher 97 not been printer independent. Even if you went back to Publisher 2000, unless you have the identical font versions and printer driver you would have issues with formatting. It sounds like the person sending you the file has a garbage HP inkjet printer. Get them to install the HP5P laser p...

Add PowerPoint 2007 to Office Basic
I have Office Basic installed on my laptop and need to add PowerPoint. What is the most recommended, easiest and least expensive way to do this? ...

I would like to know how to set up a 'fill in the blanks' form?
I would like to set up a templet of sorts to fill in the blanks for certificates. ...

Merge code issues with Publisher 2003
It seems whenever the data source is altered, the merge code fields have to be reinserted in the Publisher document. Is this normal? The data source starts in Excel and is then saved as a .txt file to retain number formatting on final merge. ...

Creating Text Box in Publisher 2007 Crashes the Application
Hello, we have a clean install of Publisher 2007 under Windows XP SP2, and when we try to create a text box in a document, (both an existing document and a blank document), publisher crashes. Office is fully patched. I ran Office Diagnostics from the help menu and no problems were found and the issue persists. Any thoughts on how to resolve the issue? Thanks, Syd See if selecting a different printer as default helps. How to view error signatures if an Office program experiences a serious error and quits http://support.microsoft.com/kb/289508/en-us -- Mary Sauer MSFT MVP http://of...

Creating a Macro to Delete Commas #2
I have an excel file that the size will varry. I need a macro that will check all the fields for a comma. If there is one I would like to get rid of it. Does anyone have any idea how to do this? I have no idea and I have been assigned this task. Help --- Message posted from http://www.ExcelForum.com/ No macro required. ctrl-H for find/replace. find , replace nothing (leave the replace field blank). You can of course record that within a macro if you wish. Drabbacs >-----Original Message----- >I have an excel file that the size will varry. I need a macro that will >check ...

Create Exchange mailbox from command line
I'm writing a script using dsadd and I was wondering if it's possible to create an exchange mailbox from the command line. Donovan Maybe not exactly what you want but it may help: http://www.joeware.net/win/free/tools/exchmbx.htm -- Neil Hobson Exchange MVP For Exchange news, links, and tips, check: http://www.msexchangeblog.com "Donovan Linton" <DonovanLinton@discussions.microsoft.com> wrote in message news:D9C839EF-883D-4E2E-8BE9-57782582F043@microsoft.com... > I'm writing a script using dsadd and I was wondering if it's possible to > create an ...

Visual C++ 2005 always rebuilds
I have an MFC DLL project that I recently moved over to Visual Studio 2005. However now the project always rebuilds entirely whenever I start debugging. Even if I have only made a simple change to one file. Any help would be greatly appreciated. Thanks Colin Check the date on your source files to make sure that they are not in the future. AliR. "Colin J Paterson" <nospam@thanks.com> wrote in message news:ObtLxgTbGHA.1196@TK2MSFTNGP03.phx.gbl... > I have an MFC DLL project that I recently moved over to Visual Studio 2005. > However now the project always rebuild...

creating a backup on 2002 for Money 98
I am helping a friend who has 98. I need to make a backup of info on my 2002 for him to use on 98. Any suggestions as to how to do this? M98 can't read any file written by M02 besides .QIF import. M02 can't write any file readable by M98 except for .QIF export. Sounds like QIF export/import is your only choice. I suspect you will find this doesn't do what you want. "Carlotte" <Carlotta41@discussions.microsoft.com> wrote in message news:015b01c3d2fa$bbf8fd60$a101280a@phx.gbl... > I am helping a friend who has 98. I need to make a > backup of info on...

SUTA state message on Pay Code Integration
I'm having trouble importing pay codes that are based on another code, such as Sick and Vacation. These records get rejected with the error message "pay code 'V' requires a SUTA state". I have a SUTA state in the Emp Maint window and the HOURLY pay code already exists and contains a SUTA state. I tried mapping the SUTA State code in my file and even tried using a Constant value in Destination mapping but these codes will not import. I can go into the Pay Code Maintenance window and add these codes manually with no problem. What am I missing? ...

MS Access 2007 code not running
I have created a brand new database in Access 2007 and linked some VB code to run on Form_Load. This code worked perfect with no problems the day I created it. Now today I opened the same form and it is not running the Form_Load code anymore (and yes it is still there, I did not delete it). I got frustrated so I copied and pasted the code to Form_Current and several On_Change events and set breakpoints at the beginning of all the events just to see if it was the Form_Load that was not triggering, but NO events are triggering my VB code. Any ideas? See this page: http://accessjunkie.com/fa...

unable to grant existing user access to TEST company
Set up test company using live company data; ran the script referenced in CustomerSource article ID#871973; can grant and remove user access in all other companies; ran grantsql 9.2; the dexsql log shows the user already has access probably because of using the other company data for the test; I can set up a new user and grant them access, existing users who already have access can view the company...but, I cannot figure out how to grant access to the TEST company to an existing user. The error popup reads "The user could not be added to one or more databases." Dynamics 9.0,...

Picture control on a form
What is the best way to fill a form with a picture control so that when the client window is resized the picture control will fill the form? -- Just Al Take a look at this and see if this is what you want: http://www.codeproject.com/dialog/bmpdlg01.asp Tom "Al" <Al@discussions.microsoft.com> wrote in message news:5BEA0FA2-3F95-4090-B908-A75DBF1D19DE@microsoft.com... > What is the best way to fill a form with a picture control so that when > the > client window is resized the picture control will fill the form? > -- > Just Al Thank You! -- Just Al &...

Null value in form not trapped by beforeupdate event
I have a form in Access 2003 linked to a SQL Server 2005 table. When I clear the value in a textbox (bound field is varchar and is required), I want the before update event to run to tell the user the value cannot be null. When I press the tab button to move to the next field after clearing the texbox, the before update event is not triggering and instead I'm getting the following error: You tried to assign the Null value to a variable that is not a Variant data type. (Error 3162) How can I prevent nulls before and this error from triggering? Thanks! ...

How export all mailbox-enabled users from the GAL using Outlook?
Hello, We have a user which, for administrative reasons, needs to export all mailbox-enabled users in the GAL now and then. They just need all the names. Is there a straightforward way for them to do that? We don't want to give them any special permissions and want to avoid server scripting. Ideally, they should be able to export it to a CSV file or any text file. Thanks, - Alan. Alan wrote: > We have a user which, for administrative reasons, needs to export all > mailbox-enabled users in the GAL now and then. They just need all the > names. Is there a straightforward way fo...

Re-enabled user account cannot log in
In trying to troubleshoot and issue in CRM where I had multiple user accounts for a single ADUC user, I tried disabling and re-enabling a user's account. But even after re-enabling the account the user cannot log in now. The error message says that it is disallowed when he tries to browse to the CRM server. Please help, I need to get this user account working again asap. Joel ...

Accessing another user's calendar OL2000/OL2003/Ex2000
Here's the situation: Running Exchange2000, v 6.0, sp4. Users are on XP/OL2003 or NT/OL2000. (we're in the process of upgrading all of the workstations to XP.) VIP user is on XP/OL2003. He can access his calendar just fine on his workstation. His secretary and other office admin type people are still on NT/OL2000. They have reviewer or editor rights to his calendar. They try to access his calendar by chosing File/Open/Other User's Folder... and put in his name and calendar. When they do this, the process hangs. In Task Manager, Outlook is "Running." End the Outloo...

Copy and close code
Hi, I have a worksheet which uses an indirect formula to search through a series of files/sheets based on an address to return a value from cell AE20. Once the data has been copied for all the previous days I would like a copy/paste values to occur to replace any of the values returned by the formula. In AU10:AU381 there is a 1 or 0 for each row. 1 meaning that a copy/pastevalues can be performed (decided by if the date is < today), and zero if i need to keep the formulas. Is it possible to have a copy/paste values code for only sheets 2-4 which works when the file is...