Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Improving an array 1

Status
Not open for further replies.

MissyEd

IS-IT--Management
Feb 14, 2000
303
GB
Hi all

In my current application I have to loop through some values whose names are based on the day of week which is in the 3 letter day of week i.e Mon, Tue, Wed, Thu, Fri, Sat, Sun

At the moment I declare an array e.g strDayArray(7) as string. Then populate it i.e strDayArray(0) = "Mon" etc.

Is there a more efficient way to do this ? I've been told maybe creating an object. Im still quite new to all this so I wondered if this is possible or if there is another way of acheiving this ?

Thanks y'all!
Missy Ed
Looking to exchange ideas and tips on VB and MS Access development as well as office 97 development. Drop me a line: msedbbw@hotmail.com
 
What are you trying to do with the array? You mentioned looping through some values whose names are based on the day of the week. Are you comparing them to something? Are you checking the validity of the data you're looping through? I guess I don't understand what you're asking if you can do better. If you could post some code or give more details that would be helpful. Snaggs
tribesaddict@swbell.net
 
I think Snaggs can be of more help, however if you are just using the "array" to look up/check some data, an enum is probably what you are looking for.

Check for it in "Help(less)"



MichaelRed
mred@duvallgroup.com
There is never time to do it right but there is always time to do it over
 
Thanks all, I'll check out that enumeration thingy. Meanwhile here is one of my subs which I use in Excel. Basically, I have the front page of my cashing up program and I dont want users to edit this directly for a number of reasons. I protect the sheet with a password and allow editing through a seperate sheet. I use this sub to update the front page with details from the edit page.

Public Sub sCommitReconciliationOfCash()
'
' Commits amendments in the reconciliation of cash
' section to the front page
'

' 1. Create
Dim frontWKSheet As Worksheet, reconWkSheet As Worksheet
Dim iDayCount As Integer, iArrCount As Integer
Dim arrNames(8) As String, strRange As String
Dim strRange2 As String, arrDay(7) As String

' 2. Initialise
Set frontWKSheet = Worksheets("Front Page")
Set reconWkSheet = Worksheets("Reconciliation of Cash")

' 2.a Populate arrays
arrDay(0) = "Mon"
arrDay(1) = "Tue"
arrDay(2) = "Wed"
arrDay(3) = "Thu"
arrDay(4) = "Fri"
arrDay(5) = "Sat"
arrDay(6) = "Sun"

arrNames(0) = "COUPONS_"
arrNames(1) = "COUPONSVAL_"
arrNames(2) = "CHEQUE_"
arrNames(3) = "CHEQUEVALUE_"
arrNames(4) = "CREDITCARD_"
arrNames(5) = "CREDITCARDVALUE_"
arrNames(6) = "CASHINTILL_"
arrNames(7) = "DATE_"

' 3. Unprotect worksheets
frontWKSheet.Unprotect "j1gglypuff2000"
reconWkSheet.Unprotect "j1gglypuff2000"

' 4. Loop to copy totals over
For iDayCount = 0 To 6
For iArrCount = 0 To 7
strRange = arrNames(iArrCount) & arrDay(iDayCount) & "_TOTAL"
strRange2 = arrNames(iArrCount) & arrDay(iDayCount) & "_TOTALA"
frontWKSheet.Range(strRange).Value = _
reconWkSheet.Range(strRange2).Value
Next iArrCount
Next iDayCount

' 5. Run formula update.
Call sUpdateFPFormula

' 6. Protect worksheets
frontWKSheet.Protect password:="j1gglypuff2000"
reconWkSheet.Protect password:="j1gglypuff2000"

' 7. Destroy
Set frontWKSheet = Nothing
Set reconWkSheet = Nothing
Erase arrDay, arrNames
strRange = ""
strRange2 = ""
End Sub Missy Ed
Looking to exchange ideas and tips on VB and MS Access development as well as office 97 development. Drop me a line: msedbbw@hotmail.com
 
VB provides a function
weekDayname(i)
This returns a string indicating the specified day of the week.

Syntax

WeekdayName(weekday, abbreviate, firstdayofweek)

So WeekdayName(3) = Tuesday
So WeekdayName(4,True) = Wed
So WeekdayName(4,True,5) = Sun
 
Thanks for the code Francis. Looks good, will try it later :) Missy Ed
Looking to exchange ideas and tips on VB and MS Access development as well as office 97 development. Drop me a line: msedbbw@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top