473,387 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Variables

I am new to VB for Excel. I do have some programming training in intro VB but I am a beginner so bear with me. Here is what I need to know for now. Let's say that I have a numeric value in cell position E5. My cell pointer is in position E6. I want to create a variable that will take on the value of E5. I create a state Dim Temp as Integer where Temp is the numeric variable. In my VB script, how do I write the command that will make Temp = to the value of E5?? I have tried such commands as:

temp = "rc[-1]"
temp = range("rc[-1]")

But not working. What would be the correct statement to put in the VB editor.??

Butch Godin
<email snipped>
Aug 10 '06 #1
5 2145
sashi
1,754 Expert 1GB
Hi there,

there are some major dif when it comes to vb and vbscript.. heard of eplicit and implicit before? sounds weird ah? :)

option explicit
-- every variable used within a particular scope must be declared with a proper datatype assignment

option implicit
-- variable need or need not to be declared to matching datatype assignment at all

vb vs. vbscript
-- with vb you have an option to declare or not to declare variable with proper datatype assignment

-- with vb script you still have an option, but this time proper datatype assignment is not a must

confused ah?

well.. refer to sample code segment below.. take care my fren..

in vb with option explicit
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Dim Str as String
  4. Dim nCount as Integer
  5.  
  6.   Str = Trim(Me.Text1.Text)
  7.   nCount = Val(Me.Text2.Text)
  8.  
in vb with option implicit
Expand|Select|Wrap|Line Numbers
  1. Option Implicit
  2.  
  3.   Str = Trim(Me.Text1.Text)
  4.   nCount = Val(Me.Text2.Text)
  5.  
in vbscript with option explicit
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Dim Str
  4. Dim nCount
  5.  
  6.   Str = Trim(Request.Form("txtName"))
  7.   nCount = Val(Request.Form("txtCount"))
  8.  
in vbscript with option implicit
Expand|Select|Wrap|Line Numbers
  1. Option Implicit
  2.  
  3.   Str = Trim(Request.Form("txtName"))
  4.   nCount = Val(Request.Form("txtCount"))
  5.  
Aug 11 '06 #2
Hi Everyone,

I'm making a stopwatch application. The Form are consisting of 4 buttons which are Start Timing, End Timing, Exit And Clear. Also it has 6 Labels. Namely
Expand|Select|Wrap|Line Numbers
  1. Label 1 Caption=Start Time
  2. Label 2=End Time
  3. Label 3=Elapsed Time
  4. Label4=BorderStyle 1-Fixed Single
  5. Caption [Blank]
  6. Name lblStart
  7. Label5=BorderStyle 1-Fixed Single
  8. Caption [Blank]
  9. Name lblEnd
  10. Label6=BorderStyle 1-Fixed Single
  11. Caption [Blank]
  12. Name lblElapsed
Now my problem is that when I click the End Timing the time is appeared without the Start Timing which is not. It should be the Start Timing first. I'm thinking of an command enabled Property and using it by If Then Else Statement.Here is the code that I did:
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Dim StartTime As Variant
  3. Dim EndTime As Variant
  4. Dim ElapsedTime As Variant
  5.  
  6.  
  7. Private Sub cmdClear_Click()
  8.   lblStart = ""
  9.   lblEnd = ""
  10.   lblElapsed = ""
  11. End Sub
  12.  
  13. Private Sub cmdEnd_Click()
  14.   EndTime = Now
  15.   ElapsedTime = EndTime - StartTime
  16.   lblEnd.Caption = Format(EndTime, "hh:mm:ss")
  17.   lblElapsed.Caption = Format(ElapsedTime, "hh:mm:ss")
  18. End Sub
  19.  
  20. Private Sub cmdExit_Click()
  21.   End
  22. End Sub
  23.  
  24. Private Sub cmdStart_Click()
  25.   StartTime = Now
  26.   lblStart.Caption = Format(StartTime, "hh:mm:ss")
  27.   lblEnd.Caption = ""
  28.   lblElapsed.Caption = ""
  29.  
  30. End Sub
Any possible solutions would be appreciated. This is my second post.. I hope someone will response. Just the concepts on how it works. Thanks..:)
Jun 29 '09 #3
MikeTheBike
639 Expert 512MB
@bsgodin
Hi

Not withstanding previouse answer, I think this should do what you require
Expand|Select|Wrap|Line Numbers
  1. Sub YourSub()
  2.     Dim Temp As Integer
  3.     If ActiveCell.Row > 1 Then Temp = ActiveCell.Offset(-1, 0)
  4.  
  5.     MsgBox Temp
  6. End Sub
I think a look at Excel VB Help may yeald some useful information for you in the future on this and many more issues !?


MTB
Jun 29 '09 #4
smartchap
236 100+
Dear Kyosuke18
In Click event of StartTime use enable event for EndTime like this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdStart_Click()
  2.  
  3.     StartTime = Now
  4.     lblStart.Caption = Format(StartTime, "hh:mm:ss")
  5.     lblEnd.Caption = ""
  6.     lblElapsed.Caption = ""
  7.     cmdEnd.Enabled=True
  8.  
  9. End Sub
  10.  
In Form Load event use:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.      cmdEnd.Enabled=False
  3. End Sub
  4.  
Now if you click cmdEnd more than once without clicking cmdStart, it will give Elapsed time from earlier Start time. IAs soon as you click cmdStart now new time will be Start Time.

Hope it is clear.
Jul 17 '09 #5
smartchap
236 100+
I think use
Expand|Select|Wrap|Line Numbers
  1. temp = Cells(5,5).Value
  2.  
It will work irrespective of current pointer position.
Jul 17 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Ross A. Finlayson | last post by:
Hi, I'm scratching together an Access database. The development box is Office 95, the deployment box Office 2003. So anyways I am griping about forms and global variables. Say for example...
9
by: CDMAPoster | last post by:
About a year ago there was a thread about the use of global variables in A97: http://groups.google.com/group/comp.databases.ms-access/browse_frm/thread/fedc837a5aeb6157 Best Practices by Kang...
7
by: misha | last post by:
Hello. I was wandering if someone could explain to me (or point to some manual) the process of mapping the addresses of host variables by DB2. Especially I would like to know when DB2 decides to...
5
by: Sandman | last post by:
I dont think I understand them. I've read the section on scope in the manual inside out. I'm running PHP 5.2.0 Here is the code I'm working on: //include_me.php <?php $MYVAR = array(); global...
1
weaknessforcats
by: weaknessforcats | last post by:
C++: The Case Against Global Variables Summary This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.