LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 415
Default VBA syntax

Arne,
Others have mentioned the type definition part, but AFAIK declaring the
objects as "ByVal" is pointless as all objects are passed by reference, the
default.
Unless I'm mistaken, but as a quick test :

Private Sub CommandButton1_Click()
Range("B3").Value = "Initial value"
Call TestByValObject(Range("B3"))
Debug.Print Range("B3").Value

Dim TestStr As String
TestStr = "Initial value"
Call TestByValStr(TestStr)
Debug.Print TestStr
End Sub

Function TestByValObject(ByVal argObject As Range)
argObject.Value = "If really ByVal, you cannot see this change."
End Function

Function TestByValStr(ByVal argString As String)
argString = "If really ByVal, you cannot see this change."
End Function

NickHK

"Arne Hegefors" ...
Hello! I have become somewhat unsure of certian things regarding the
syntax
in vba. therefor I would truly appreciate answers to the following
questions:

1) In the beginning of a sub that takes two arguments do you have to
write:
Private Sub checkReturnDifference(ByVal rng1 As Range, ByVal rng3 As
Range)
or can you write ....(ByVal rng1, rng3 As Range)

2) When declaring new variables is it necessary to write:
Dim i As Integer
Dim k As Integer
....
or is there a shorter way of doing this?

I know that these questions does not seem very important but when you have
meny variables then it does actually make a difference. thus, any help
appreciated! thank you all very much!



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
IF, THEN SYNTAX BBABBZZ Excel Worksheet Functions 5 January 12th 10 10:11 PM
Syntax help please GettingThere Excel Programming 3 August 19th 05 01:25 AM
Syntax help! Mike Fogleman Excel Programming 20 July 30th 05 01:11 PM
If then syntax RL Excel Worksheet Functions 3 June 22nd 05 05:30 AM
Help with VBA syntax jacqui[_2_] Excel Programming 3 January 13th 04 02:29 PM


All times are GMT +1. The time now is 06:07 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"