Which Is The Most Efficient?
I'm just making my own type for holding the info of a map (rpg style sort of)(tile based at least)...
And I'm not really sure how to declare this before I shall go on, which is the best way:
Code:
Public Type MapArray Tile As Integer Passable As Boolean End Type
Public Map() As MapArray
Like that, with an array which is of type MapArray?
or just use:
Code:
Tile() As Integer Pass() As Boolean
multiple arays? By the way, I'm planning on storing the data in a file as Binary, if that matters...
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
More Efficient Way Of Doing This – HELP
Hey guys I just got into this and I just learned BitBlt yesterday. So this is my problem I want to make the animation for my game and i made this example and this is how I made it animate
Code:
Private Sub Timer2_Timer()
frame = frame + 1
Select Case frame
Case 1
posX = 0
Case 2
posX = 40
Case 3
posX = 80
Case 4
posX = 120
Case 5
posX = 168
Case 6
posX = 216
Case 7
posX = 264
Case 8
posX = 312
Case 9
posX = 360
Case 10
Timer2.Enabled = False
End Select
End Sub
so basiclly it uses a timer to check which frame it should display. As you can see this take to much time ( for big games) and it slows the program down. Could someone tell me a better way of doing this ? I thought of taking the first frame then * by the frame but my sprites arent set up that way.
Here is the full source code
More Efficient?
Which would you say is a better idea for a tile-based game?
Creating a map in a text file (using numbers to represent tiles), loading the map into a 2D-array and rendering the map tile by tile (applying a texture to each tile)?
Or
Creating a map in a text file as above, drawing out the map once (during run-time), saving the complete map as a new picture, then using that as a texture over one big square for the map?
In short, many small tiles with individual textures? or one big tile with one texture?
Which Is More Efficient?
I've found three ways of doing the same thing, and I want to know which is most efficient. Basically, if the boolean variable DII is true, then the variable u needs an asterisk (*) before it. Below are the three examples.
Code:
'Type 1
If DII Then
Display "/w *" & u
Else
Display "/w " & u
End If
'Type 2
If DII Then u = "*" & u
Display "/w " & u
'Type 3
Display "/w " & IIf(DII, "*", "") & u
Which of these is the fastest and most efficient method? My bets are on 3, but I've been wrong about efficiency in VB6 before, so I'd like to double-check.
How To Be More Efficient
Hello,
I have been playing around with vb for a little while and well I wanted to improve my style and I was wondering if any of you guys could give a me a couple of suggestions.
I am looking to recycle code that I use frequently in my vb projects and I am not sure how I should go about it? I mean I sometimes created a public sub on my first form and access it with my other forms but I was wondering their was a better way of doing this? (So basically I don't end up copy and pasting the same code everywhere.)
YOu guys don't have a to type too much you can refer me to a article or some info on the web, i'll do the rest!
Well thanks alot!
Fraggy
A More Efficient Way?
I have a text file that I have paresed and reformated into a file called "switch.txt" The new text file is 2600+ lines (records) which I am inputing into an Access database table.
I had the application working at one point, when the database was locally on my machine. However when I tried to use it with the live database on the network it wouldn't work, so I started redesigning. The problem is that it starts reading the text file into the DB like gangbusters, but after about 600 records it starts to slow down, to the point where it seems to almost come to a stop (I've never waited to see how long it takes after I waited 15 min. for it to run).
My question: Have I designed this poorly and if so what is a better way to get the text information into the DB?
as always thanks in advance
Bart
Code:
Option Explicit
Dim oConn As ADODB.Connection
Dim sConn As String
Dim sSQL As String
Private Sub GetDMSData() 'Read data from Switch text file into an array using split()
Dim iFile As Integer
Dim sPhnum As String
Dim sPre As String
Dim sEquip As String
Dim sString As String
iFile = 1
Open App.Path & "switch.txt" For Input As iFile
Do While Not EOF(iFile)
Dim arrSwitch() As String
Line Input #iFile, sString
sPre = Mid$(sString, 3, 3)
sPhnum = Mid$(sString, 6, 4)
sEquip = Mid$(sString, 17, 7)
sString = sPre & " " & sPhnum & " " & sEquip
arrSwitch = Split(sString, " ")
PopTable arrSwitch
Loop
End Sub
Private Sub PopTable(sInput() As String)
'Dim rs As ADODB.Recordset
' This is what I have now
'Input data from array in GetdmsData to dms table in DB
sSQL = "INSERT INTO [DMS] VALUES '" & sInput(0) & "', '" & sInput(1) & _
"', '" & sInput(2) & "'"
OpenConnection
oConn.Execute sSQL
oConn.Close
'[indent] ' I Also tried this........................
' sSQL = "SELECT * FROM DMS"
' OpenConnection
' Set rs = New ADODB.Recordset
' rs.Open sSQL, oConn, adOpenDynamic, adLockOptimistic
' rs.AddNew
' rs!Pre = sInput(0)
' rs!Phone = sInput(1)
' rs!Equip = sInput(2)
' rs.Update
' rs.Close
' oConn.Close[/indent]
End Sub
Public Sub OpenConnection()
sConn = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = F:
etworkdrivemydb.mdb"
Set oConn = New ADODB.Connection
oConn.Open sConn
End Sub
Which Is More Efficient?
Approach 1:
Code:
p = MyArray1(362,419)
For i = 0 To 2000
For j=0 To 780
MyArray2(i,j) = p
Next
Next
Approach 2:
Code:
For i = 0 To 2000
For j=0 To 780
MyArray2(i,j) = MyArray1(362,419)
Next
Next
In other words, accessing a variable is more or less efficient than accessing a specific array element?
The Most Efficient Way To Do Nothing
My program will run scheduled (every half hour or so) tasks. Is code in a timer sub a more efficient way to wait than using Sleep API? My program will likely be doing NOTHING else during this time, so I want it to not lag my computer. Thx
Which Is More Efficient
probably completly insignificant but which do you think is the faster method,
VB Code:
If Not strtrack = vbNullString Then
or
VB Code:
If strtrack <> vbNullString Then
Efficient SQL
I have a table of customers and a table of products that the customer have so the join is a one to many because there will be one customer record and possibly many product records.
When I want to query this to load data into a class I made, is it more efficient to query using a join, or seperate calls to the tables
for example if i do a join i will get the customer information with each record
Code:
NAME ID PRODUCT ID PRODUCT DESC
john smith 1 3 BALL
john smith 1 4 BOX
john smith 1 6 PIPE
versus doing a call to just get customer info and using the customers ID to get the products in a second sql call?
What Would Be More Efficient ...
Considering both memory usage and processing time, what would be more efficient:
(1) Have a control array of 250 labels defined on the form at design time, initially not visible, and make a particular label visible when needed (on average, maybe only 20 of these will be shown).
- or -
(2) Just define the initial lablel (Index = 0) on the form, and dynamically generate the extra ones as needed at run-time.
Which One Is More Efficient?
Which one do you think it is more idealistic?
-Use arrays to store large amount of text -- would this slow down the program?
-Save the text to a file and import the text back in at the end of the program
Basically, I am stripping a fair amount of data out of a document, format the document and stick the data back in.
Thanks
Most Efficient Way
Hi,
I am currently doing a project in which I also have to make an
student attendance module.Can anyone please suggest how I should proceed or which is the most efficient way of maintaining the students attendance??
I have Access as the backend.
Which One Is More Efficient...
hi,
while using ADOs....
....v can use either SetComplete / SetAbort for Recordset or
....v can use BeginTrans, CommitTrans / RollbackTrans for ADO Connection...
can anyone explain which one is more efficient..and in what way...
thanks in advance
Is This Efficient ?
i've written a code for producing out perfectly random nos in a set.but it uses labels , i've heard that using labels is not good programming practice.
public function getall(lim as integer) as integer()
Dim arr(lim) As Integer
Dim i As Integer
Dim j As Integer
Dim num As Integer
Randomize
arr(i) = Rnd * 10 1
i = i + 1
Do While i <= lim
seed: num = Rnd * 10 1
For j = 0 To i - 1
If num = arr(i) Then GoTo seed
Next
arr(i) = num
If i = lim Then Exit Do else i=i+1
Loop
getall=arr()
End Sub
u can dload a working activeX exe based on this from
www.geocities.com/vishalmungi
p.s : Sorry for low documentation sense.
What's The Most Efficient Way.
Hi,
Kinda new to programming here.
Here's my question. I am making an internet game.
I am in the process of polishing the server and the client part of the program up.
I have found a need to use USER AUTHENTICATION so nobody can steal each others names and game data.
So when a client logs into the server, the first thing the server needs is a username and password.
I know how to send and receive that information, I am just wondering how I am going to make the server check the information.
Database
username.txt <----txt file has password in it
or another way.
If I had it way (wishful thinking) thousands of people will play my game. What would be the fastest and most effcient way to check a username to a password. I was thinking the text file but then I could have thousands of files on the computer.
Let me know what you think...
Vince
CPU Efficient
Is there a way in VB to make a program more CPU efficient?
I have three applications which work in coordination. And it seems if one of them consumes too much CPU the other one
aborts.
Thank you
What Is More Efficient?
I have a form that will, upon users intevention, automatically bring up a second form.
What is more efficient:
Have the form2 load up as the form2 is needed or have both forms load together and set the visible properties of form2 to false until it is needed? (I am concenred about processor and memory usage.) -Note- It may be possible that form2 might not even be needed.
Your help is greatly appreciated,
Daniel Christie
Looking For An Efficient Way To Get ID
What would be the best way to get the ID field(auto-numbered key) of a record that was just inserted with ADO? Currently, I am opening the recordset, moving to the first record and looping through until I reach the last record and then I get the ID of the last record. This is not very effective as my table has 112,000 records and this can't be the fastest way. Any suggestions would be great!
Thanks,
Greg
DirectInput : Which Is More Efficient?
I have a question about DirectInput.
I have a Key array that holds the CONST_DIKEYFLAGS and a RefreshKeyboard sub that looks like this:
Code:
Public Sub RefreshKeyboard()
Dim i As Integer
'Get keyboard state
DI_KeyBoard.GetDeviceStateKeyboard KeyboardState
'Store all keystates in array
For i = 1 To 211
If KeyboardState.Key(i) <> 0 Then
Key(i) = True
If HappenedOnce(i) = True Then
Key2(i) = False
Else
Key2(i) = True
HappenedOnce(i) = True
End If
Else
Key(i) = False
Key2(i) = False
HappenedOnce(i) = False
End If
Next
End Sub
You can ignore the HappenedOnce and Key2 arrays for now, they're my un-optimized way of processing a key pressed one time until it's released. RefreshKeyboard gets called once per loop.
To test a key I simply use this sub:
Code:
'returns true if key is being pressed
Public Function GetKey(lKey As CONST_DIKEYFLAGS) As Boolean
GetKey = Key(lKey)
End Function
'then I use it like this:
If GetKey(DIK_ESCAPE) Then bRunning = False
My question is, would it be more efficient or faster to update only they key being requested when GetKey is called, instead of calling RefreshKeyboard each game loop for every key?
I was thinking of something like this:
Code:
Public Function GetKey(lKey As CONST_DIKEYFLAGS) As Boolean
DI_KeyBoard.GetDeviceStateKeyboard KeyboardState
GetKey = KeyboardState.Key(lKey)
End Function
'It would still be used the same way:
Of GetKey(DIK_ESCAPE) Then bRunning = False
This seems much more efficient and I want to know which way is best. Thanks for your time
Efficient Code
Hello everybody,
Can any one provide me general guidelines for efficient code - criteria - in VB?
Any documentation or link for this subject available in this forum? pl forward the link.
Thanks for reading,
Sejal
Efficient Algorithm
Lets say I want to make some calculations which use 9 variables: X1, X2, X3, ... X9. I want these variables to have the values 1 through 9 with no two variables having the same value and my calculations would be done on all possible permutations of these 9 variables.
In pseudo code, I can do something like this:
For X1 = 1 to 9
For X2 = 1 to 9
If X2 = X1 Then Next X2
For X3 = 1 to 9
If X3 = X2 Then Next X3
If X3 = X1 Then Next X3
For X4 = 1 to 9
If X4 = X3 Then Next X4
If X4 = X2 Then Next X4
If X4 = X1 Then Next X4
and so on
This approach works fine, but seems to me to be very inefficient, especially as the number of variables increases.
Does anyone have a more efficient way of assigning values to variables as I've described?
Thanks for your time.
Anthony Felder
Efficient Code...
On an ASP page which would be the better use of creating the DLL?
Creating it and destroying it inside each function call(as below) or to create it at the TOP of the page and essentially SHARE it?
Thanks
Code:
:--------------------------------------------------------------------------------
'###################################################################################################
#
function GetUsers(byval intChatid)
set Chat = server.CreateObject ("Chat.Utilities")
set GetUsers = Chat.RunSPReturnRS(CONNECTION_STRING, "db_GetUsers", _
Array(Array("id", adInteger, adParamInput, 4, intChatid)), Null)
set Chat = nothing
end function
'###################################################################################################
#
function GetUserRole(byval intUserId, byval intChatRoomID)
set Chat = server.CreateObject ("Chat.Utilities")
set GetUserRole = Chat.RunSPReturnRS(CONNECTION_STRING, "db_GetUserRole", _
Array(Array("ChatRoomID", adInteger, adParamInput, 4, intChatRoomID), _
Array("UserID", adInteger, adParamInput, 4, intUserId)), Null)
set Chat = nothing
end function
'###################################################################################################
#
function SetUserActivity(byval intUserId, byval intActivityStatus)
' intActivityStatus 1 = Active
' intActivityStatus 0 = InActive
set Chat = server.CreateObject ("Chat.Utilities")
Call Chat.RunSP(CONNECTION_STRING, "db_SetUserActivity", _
Array(Array("id", adInteger, adParamInput, 4, intUserId), _
Array("isActive", adInteger, adParamInput, 5, intActivityStatus)), Null)
set Chat = nothing
end function
Any Work Around For In-efficient IFs
Visual Basic seems to check all conditions of an IF statement even if an earlier one fails (when using with chained ANDs) which is either an oversight by them or there's a combination which defies the rule.
Is there a work around for this or is the only way to split the IF statement into a nested IF?
example:
Code:
If Len(txtbox.Text) > 0 and txtbox.Text <> ":" and Dir(txtbox.Text) = "" then
'do something
Else
'blah
End if
This produces when txtbox.Text = ":" since Dir() will return an error, which means it has been checked even though it failed the second AND.
Working one is:
Code:
If Len(txtbox.Text) > 0 and txtbox.Text <> ":" then
If Dir(txtbox.Text) = "" then
'do something
End if
Else
'blah
End if
More Efficient Code
The code below was written to take the values in my recordset insert the values to my grid. The program runs fairly fast until it reaches this chunk of code...then.....my program either freezes.....or it takes about 3 minutes to output 500 rows (6 columns) of data. That is terrible. This is the code I am using to fill my grid. Is there a better way of writing this? I mean some of my queries are going to return 50,000 rows of data.
Can someone please shoot me some ideas....
'Add the data under each column header
recordcount = RS.recordcount
columncount = RS.Fields.count
iNumCols = RS.Fields.count
iNumRows = RS.recordcount
vardata = RS.GetRows(iNumRows)
CountTxt.Text = RS.recordcount
For intIrow = 1 To (iNumRows)
For intICol = 1 To iNumCols
Grid1.Cells((intIrow + rowskip), intICol).Value = vardata(intICol - 1, (intIrow - 1))
Grid1.Cells.AutoFitColumns
If StopProcess = True Then Exit For 'EXIT IF THE "CANCEL" BUTTON IS HIT
Next intICol
Next intIrow
-------------------------------------------------------------------
NOTE: The 'rowskip' variable is used to tell the program to either start outputting data on row 6 or row 7. If the user has a report header output rows starting on row 7 in there is no header then start the output on 7.
Most Efficient Way To Search?
Hi All,
I'm trying to set up an array with at least 400,000 different variables and I need to bounce them against another file for verification purposes. I have sorted my array before I loaded it and now I need to figure out a way to search through the array without examining every array variable sequentially till I find a match. What I mean is.... Can I do a binary search of the array or does it have to be sequential? Is there a way to go straight to the "G" section of the array with out reading through the "A" - "F" part?
Thanks in advance,
-NJDevils28
Efficient Way To Localise
Hi!
I would like to let my application be localised freely by the users. This is why I decided to use text files with all the captions and other text.
What would you recommend to make this process as efficient as it could be? I have constructed a little function that returns the value of a desired line, but I don't believe such a way is very efficient, especially if there are many objects on a form (and also if the file with localised captions is very big) - or AM I WRONG? Anyways this is my function
Code:
Public Function GetCaption(LineNumber As Integer) As String
Dim i As Integer, bStop As Boolean
Dim strTemp As String
i = 0 'Current line number
bStop = False 'Desired line number hasn't been read
Open App.Path & "slo.lng" For Input As #1
Do
i = i + 1
Line Input #1, strTemp
If i = LineNumber Then
GetCaption = strTemp
bStop = True
End If
Loop Until bStop = True
Close #1
End Function
Do you have any other idea?
Thanks,
Bostjan
Code Not Efficient...help!!!
I have this piece of long code which I have difficulties in making it more
efficient. What it does is that it reads the total number of terms from
calendarwk.dbf and store the term no and it number of weeks in an
array.
Next it reads the wpweek.dbf and workplan.dbf and retrieves it number
of workplans in the term.
Then it will access the wpweek.dbf and try to duplicate the data into a
new dbf file call abc.dbf. However the output data is dependent on the calendarwk.dbf.
E.g in Calendarwk.dbf term 1 has 13 weeks while wpweek.dbf has only
11 week.
The code will try calculate the diff in weeks from both db. If found more
week, then it will add on into the abc.dbf file.
This is what the code does below. However I find that my method is
rather not efficient.
Can anyone who has better understanding/coding abilities help to make it runs more efficiently???
thank you!
kelvin
Code:
Private Sub ModifyWkpln_Click()
Dim strSQL, insStr, test, numRec, results As String
Dim termCnt() As Integer
Dim wpWeekCnt() As Integer
Dim tmpWkPlnID, extraWeeks, x, y, z, i, k As Integer
Dim termNo, totalCalWeeks, totalWkplnWeeks As Integer
Dim wkCnt, tmpCnt, tmpCnt2, tmpCnt3, tmpCnt4 As Integer
Dim rs As ADODB.Recordset
Dim rs2 As ADODB.Recordset
termNo = 0
conADO.Execute "CREATE TABLE abc (WorkPlanID Numeric, WeekNo " & _
"Numeric, ThemeID Numeric, State Numeric)", , adExecuteNoRecords
'==============================================
Set rs = New ADODB.Recordset
'get the term and its num of weeks from calendarwk.dbf
strSQL = "SELECT DISTINCT termno, COUNT(termno) as cnt From calendarWK GROUP BY termno"
rs.Open strSQL, conADO
rs.MoveFirst
While Not rs.EOF
ReDim Preserve termCnt(x)
termCnt(x) = rs.Fields("cnt")
rs.MoveNext
x = x + 1
Wend
'==============================================
Set rs = New ADODB.Recordset
'get the term and its num of weeks from wpweek.dbf & workplan.dbf
strSQL = "SELECT DISTINCT workplan.termno, COUNT(wp.workplanid) AS cnt " & _
"FROM wpweek wp, workplan " & _
"Where wp.workplanid = workplan.workplanid " & _
"GROUP BY wp.workplanid, workplan.termno "
rs.Open strSQL, conADO
rs.MoveFirst
While Not rs.EOF
ReDim Preserve wpWeekCnt(k)
wpWeekCnt(k) = rs.Fields("cnt")
rs.MoveNext
k = k + 1
Wend
'==============================================
Set rs2 = New ADODB.Recordset
strSQL = "SELECT DISTINCT w.workplanid, w.termno, wp.themeID, wp.weekno " & _
"FROM workplan w, wpweek wp " & _
"WHERE w.workplanid = wp.workplanid " & _
"ORDER BY w.termno ASC, w.workplanid ASC, wp.weekno ASC "
rs2.Open strSQL, conADO
MousePointer = vbHourglass
'access the database(db). Read the content of db.
'Check if calendarwk.dbf has more weeks. If has more weeks, add new weeks.
rs2.MoveFirst
While Not rs2.EOF
termNo = rs2.Fields("termno")
'return total weeks in one term from calendarWK.dbf
totalCalWeeks = termCnt(termNo - 1)
'return total weeks in one term from wpWeek.dbf
totalWkplnWeeks = wpWeekCnt(termNo - 1)
extraWeeks = totalCalWeeks - totalWkplnWeeks
wkCnt = wkCnt + 1 'record count
If termNo = 1 Then
If wkCnt <= totalWkplnWeeks Then
insStr = "INSERT INTO abc VALUES (" & rs2.Fields("workplanID") & _
", " & rs2.Fields("weekNo") & ", " & rs2.Fields("themeID") & ", 1)"
conADO.Execute insStr, numRec, adExecuteNoRecords
tmpWkPlnID = rs2.Fields("workplanID")
If wkCnt = totalWkplnWeeks And extraWeeks > 0 Then
For y = 1 To extraWeeks
wkCnt = wkCnt + 1
insStr = "INSERT INTO abc VALUES (" & tmpWkPlnID & ", " & wkCnt & ", " & 0 & ", 1)"
conADO.Execute insStr, numRec, adExecuteNoRecords
Next y
tmpCnt = wkCnt
tmpCnt2 = tmpCnt
wkCnt = 0
End If
End If
termChange = False
ElseIf termNo = 2 Then
tmpCnt2 = tmpCnt2 + 1
If wkCnt <= totalWkplnWeeks Then
insStr = "INSERT INTO abc VALUES (" & rs2.Fields("workplanID") & _
", " & tmpCnt2 & ", " & rs2.Fields("themeID") & ", 1)"
conADO.Execute insStr, numRec, adExecuteNoRecords
tmpWkPlnID = rs2.Fields("workplanID")
If wkCnt = totalWkplnWeeks And extraWeeks > 0 Then
For y = 1 To extraWeeks
y = y + tmpCnt2
insStr = "INSERT INTO abc VALUES (" & tmpWkPlnID & ", " & _
y & ", " & 0 & ", 1)"
conADO.Execute insStr, numRec, adExecuteNoRecords
Next y
tmpCnt2 = tmpCnt
tmpCnt3 = totalCalWeeks + tmpCnt
wkCnt = 0
End If
End If
ElseIf termNo = 3 Then
tmpCnt3 = tmpCnt3 + 1
If wkCnt <= totalWkplnWeeks Then
insStr = "INSERT INTO abc VALUES (" & rs2.Fields("workplanID") & _
", " & tmpCnt3 & ", " & rs2.Fields("themeID") & ", 1)"
conADO.Execute insStr, numRec, adExecuteNoRecords
tmpWkPlnID = rs2.Fields("workplanID")
If wkCnt = totalWkplnWeeks And extraWeeks > 0 Then
For y = 1 To extraWeeks
y = y + tmpCnt3
insStr = "INSERT INTO abc VALUES (" & tmpWkPlnID & ", " & _
y & ", " & 0 & ", 1)"
conADO.Execute insStr, numRec, adExecuteNoRecords
Next y
tmpCnt3 = tmpCnt + totalCalWeeks
wkCnt = 0
End If
End If
End If
Wend
MousePointer = vbDefault
End Sub
More Efficient SQL Select
How can I rewrite this without the UNION?
I tried using an OR in the WHERE clause but that did not return any records.
Code:
' Set gmRS = gmDB.Execute("SELECT contact1.accountno,contact1.key1,contact1.company,contact1.address1,contact1.address2,contact1.city,contact1.state,contact1.zip,contact1.fax,contact1.phone1,contact1.recid,contact1.contact," & _
' "contsupp.accountno AS contsuppAccountno,contsupp.contsupref,contsupp.address2 AS contsuppAddress2,contsupp.recid AS contsuppRecid,contsupp.contact AS contsuppContact, contsupp.rectype, contsupp.fax as contsuppFax, contsupp.zip as contsuppZip, contsupp.phone as contsuppPhone" & _
' " FROM contact1 LEFT JOIN contsupp " & _
' " ON contact1.accountno = contsupp.accountno" & _
' " WHERE [rectype] = 'p' AND [contsupp.contact] = 'e-mail address' AND ([contsupp.phone] = 'x+3[][><!' OR [linkacct] is not null OR [contsupp.zip] = '0111')" & _
' " UNION " & _
' "SELECT contact1.accountno,contact1.key1,contact1.company,contact1.address1,contact1.address2,contact1.city,contact1.state,contact1.zip,contact1.fax,contact1.phone1,contact1.recid,contact1.contact," & _
' "contsupp.accountno AS contsuppAccountno,contsupp.contsupref,contsupp.address2 AS contsuppAddress2,contsupp.recid AS contsuppRecid,contsupp.contact AS contsuppContact, contsupp.rectype, contsupp.fax as contsuppFax, contsupp.zip as contsuppZip, contsupp.phone as contsuppPhone" & _
' " FROM contact1 LEFT JOIN contsupp " & _
' " ON contact1.accountno = contsupp.accountno" & _
' " WHERE [rectype] = 'c'")
ByRef Very Efficient?
Hey how efficient is ByRef? It's a pointer argument right? So I would say it'd take up a Long (4 bytes)?
For example,
say I have a procedure in a module that does work depending on the form specified.
Below are two versions of this function, do which one is more efficient, or do they perform the same?
1) Passing the whole Form with ByRef
Public Sub HandleForm(ByRef frmForm As Form)
Select Case frmForm.hWnd
Case frmTest1.hWnd
...
Case frmTest2.hWnd
...
End Select
End Sub
2) Passing only the form handle
Public Sub HandleForm(llFormHWnd As Long)
Select Case llFormHWnd
Case frmTest1.hWnd
...
Case frmTest2.hWnd
...
End Select
End Sub
More Efficient If Statement
Sometimes when I make an if statement, it just seems a little bit inefficient. For example:
VB Code:
if right(text1,1) = "2" or right(text1,1) = "4" or right(text1,1) = "6" o right(text1,1) = "8" or right(text1,1) = "0"return "even"end if
How do I do that type of if statement without using so many ORs?
RESOLVED * How To Do This The Most Efficient Way
Hi,
What I have is a list with x,y,z coordinates (I.e. x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4.. etc)
I split the list, and put the X, Y, Z coordinates in three seperate arrays: arListX, arListY, arListZ.
The problem is that some coordinates have more then one occurence in the list with coordinates. (x1,y1,z1) = (x3,y3,z3)
What I need to do is to filter out all the double occurences in my list.
And after that I need to have the list sorted.
The sorting has to be done in the order x,y,z
x1 = 50 y1 = 12 z1 = 25
x2 = 75 y2 = 12 z2 = 25
x3 = 50 y3 = 10 z3 = 25
x4 = 60 y4 = 12 z4 = 37
x5 = 30 y5 = 10 z5 = 37
x6 = 60 y6 = 10 z6 = 37
x7 = 60 y7 = 10 z7 = 25
x8 = 60 y8 = 12 z8 = 25
this should become:
x1 = 30 y1 = 10 z1 = 37
x2 = 50 y2 = 12 z2 = 25
x3 = 60 y3 = 10 z3 = 25
x4 = 60 y4 = 10 z4 = 37
x5 = 60 y5 = 12 z5 = 25
x6 = 60 y6 = 12 z6 = 37
x7 = 75 y7 = 12 z7 = 25
Thanks anyway,
mvrp350
Can It Be Made More Efficient?
I have the following code:
VB Code:
FlexGrid.Row = WordInfo(num).YSpot - y1spot 'Set the row - constant For i = 1 To Len(WordInfo(num).Word) 'Go through each letter in the word FlexGrid.Col = WordInfo(num).XSpot - x1spot - 1 + i 'Set the current column FlexGrid.CellBackColor = DisHighColor 'Set the background color to yellow If FlexGrid.CellForeColor <> vbBlack Then 'If the foreground is NOT black (a letter from another word) FlexGrid.CellForeColor = DisHighColor 'Set the foreground to white End IfNext i
When I use that, it highlights a series of cells in a flexgrid (I am making a crossword)...
Thanks
Efficient Code...
On an ASP page which would be the better use of creating the DLL?
Creating it and destroying it inside each function call(as below) or to create it at the TOP of the page and essentially SHARE it?
Thanks
Code:
'####################################################################################################
function GetUsers(byval intChatid)
set Chat = server.CreateObject ("Chat.Utilities")
set GetUsers = Chat.RunSPReturnRS(CONNECTION_STRING, "db_GetUsers", _
Array(Array("id", adInteger, adParamInput, 4, intChatid)), Null)
set Chat = nothing
end function
'####################################################################################################
function GetUserRole(byval intUserId, byval intChatRoomID)
set Chat = server.CreateObject ("Chat.Utilities")
set GetUserRole = Chat.RunSPReturnRS(CONNECTION_STRING, "db_GetUserRole", _
Array(Array("ChatRoomID", adInteger, adParamInput, 4, intChatRoomID), _
Array("UserID", adInteger, adParamInput, 4, intUserId)), Null)
set Chat = nothing
end function
'####################################################################################################
function SetUserActivity(byval intUserId, byval intActivityStatus)
' intActivityStatus 1 = Active
' intActivityStatus 0 = InActive
set Chat = server.CreateObject ("Chat.Utilities")
Call Chat.RunSP(CONNECTION_STRING, "db_SetUserActivity", _
Array(Array("id", adInteger, adParamInput, 4, intUserId), _
Array("isActive", adInteger, adParamInput, 5, intActivityStatus)), Null)
set Chat = nothing
end function
Most Efficient Way To Sort This?
I need to loop through a collection of Items with 2 properties, a numeric key and a text key.
I need to then write all the text keys ordered primarily by the numerical key, but secondarily by the text key in the event that 2 numerical keys are the same.
Any idea what the most efficient way to code this would be?
What Is The Efficient Way To End My Prog?
what happend if i create some exit button on my prog and set it like this when i want to exit it
Private Sub cmdClose_Click()
Set All = Nothing
End
End Sub
If i used db connection, should i close it too?
Can Anyone Tell Me Which Method Is More Efficient?
Could someone help me determine which way is better. I have a bunch of Select Case Statements the first way. Does it save memory to do this the second way, or do you sacrifice speed because it checks more if then statements where as a case statement is more direct. But, the second way has way less code and repetition.
Thanks,
Jeff
Select Case Stations
Case 2:
Dwell(0) = Text1
Dwell(1) = Text2
StationName(0) = Combo1(0)
StationName(1) = Combo1(1)
Case 3:
Dwell(0) = Text1
Dwell(1) = Text2
Dwell(2) = Text3
StationName(0) = Combo1(0)
StationName(1) = Combo1(1)
StationName(2) = Combo1(2)
Case 4:
Dwell(0) = Text1
Dwell(1) = Text2
Dwell(2) = Text3
Dwell(3) = Text4
StationName(0) = Combo1(0)
StationName(1) = Combo1(1)
StationName(2) = Combo1(2)
StationName(3) = Combo1(3)
Case 5:
Dwell(0) = Text1
Dwell(1) = Text2
Dwell(2) = Text3
Dwell(3) = Text4
Dwell(4) = Text5
StationName(0) = Combo1(0)
StationName(1) = Combo1(1)
StationName(2) = Combo1(2)
StationName(3) = Combo1(3)
StationName(4) = Combo1(4)
Case 6:
Dwell(0) = Text1
Dwell(1) = Text2
Dwell(2) = Text3
Dwell(3) = Text4
Dwell(4) = Text5
Dwell(5) = Text6
StationName(0) = Combo1(0)
StationName(1) = Combo1(1)
StationName(2) = Combo1(2)
StationName(3) = Combo1(3)
StationName(4) = Combo1(4)
StationName(5) = Combo1(5)
End Select
or the following....
If (Stations = 2) Or (Stations > 2) Then
Dwell(0) = Text1
Dwell(1) = Text2
StationName(0) = Combo1(0)
StationName(1) = Combo1(1)
End If
If (Stations = 3) Or (Stations > 3) Then
Dwell(2) = Text3
StationName(2) = Combo1(2)
End If
If (Stations = 4) Or (Stations > 4) Then
Dwell(3) = Text4
StationName(3) = Combo1(3)
End If
If (Stations = 5) Or (Stations > 5) Then
Dwell(4) = Text5
StationName(4) = Combo1(4)
End If
If (Stations = 6) Or (Stations > 6) Then
Dwell(5) = Text6
StationName(5) = Combo1(5)
End If
Efficient And Fast..
whats more efficient and faster running, calling a function like this:
Call whatever(blah, blah, blah)
or:
whatever blah, blah, blah
it can be done either way, but which one would perform faster?
just a simple question of format..
Efficient Coding??
Well I'm trying to cut down my code, tyring to make it more efficient. I'm hoping you VB experts can clarify a few things for me:
1) I noticed that most of the combo boxes and text boxes call the same function. Is there a way to make a general event procedure for all combo boxes? Like for all combo boxes that undergo the click event I execeute so and so. Is this possible? I know control arrays can achieve this, but I don't want to create a control array, I need my objects to be unique.
2) There are times when I need to edit a certain property for all text boxes (or any other objects), Is there a way to change all of them without calling each object? Can I somehow use a loop?
3) This has nothing to do with efficient coding, it just popped in my mind , How do I make those line seperators in the menu? I want to partition my menu options just like how vb and other application do it
Thanks again for all the help! Hope to learn somethign new again from you guys
Is One More Memory Efficient?
Hi guys,
I have a group of functions that can quite happily work as a class. IS there any benifit to the memory consumption or performance?
}...the bane of my life!
http://www.fuzzyd.co.uk
Most Efficient Use Of ADO When Looping?
I have a program, written as a service, that periodically opens all the files in a specific directoy, parses them out and sends the results to a stored procedure (SQL server is localhost) to be processed and stored away. Then it deletes the file and moves to the next. I've tried it a couple different ways and although it works fine, it seems pretty slow to me. I have a generic example of the way I'm currently doing it, was wondering if anyone sees any obvious traps?
CODEsub main
'dim variables, setup cnn object and open connection here
curFile = Dir(myPath)
do while curFile <> ""
'for every file I open I recreate the command and prm 'objects. I suppose I could do this once, globally, but 'this part of the process is really not slow
Set cmd = New ADODB.Command
cmd.ActiveConnection = cnn
cmd.CommandText = "spCountPoints"
cmd.CommandType = adCmdStoredProc
Set prmNode = cmd.CreateParameter("Node", _
adVarChar, adParamInput, 50, node)
cmd.Parameters.Append prmNode
'5 more prm's after this one
Open cuFile for input as #fileNum
Do while not EOF(FileNum)
'line input, and parse out the text here
prmNode.value = sNode
'5 more prm.values set here
'each line parsed in the file gets a sql call
cmd.execute
loop 'go to next line
close #filenum
kill curFile
set prm's & cmd = nothing
loop ' next file
'all files are done
cnn.close
set cnn = nothing
Efficient Code
I've got a module where a record set parameter is passed to a procedure. I'll be using this record set in many other procedures in this module.
There is also a global word object that exists.
This is how the code currently is but I want to write a new module as efficiently as possible.
Here are my questions:
1.) Should I keep passing the recordset from procedure to procedure as a paramter or make it a modular object? I will be referencing each field from it only once.
2.) I want to create another object from the Word object to process the docvariables.
CODESet objActiveDoc = AppWd.ActiveDocument
Set objDocVariables = objActiveDoc.Variables
Maybe A Loop Would Be More Efficient?
hi all, im trying to create a search that allows you to search if a shop has a record. i have made one that works however i think that it would be better as a loop, but i couldnt seem to do it, mayne someone could help?
basically all the code below does is check if the search text equals part of the array, if not it adds 1 and then checks again and so on... heres what i have:
Private Sub Cmdsearch_Click()
Dim recordsearched As String
Dim found As Boolean
index = 1
found = False
recordsearched = Txtsearch.Text
'1st if
If recordsearched = record(index) Then
found = True
Else
found = False
End If
If found = True Then
MsgBox "record found"
Else
index = index + 1
End If
'2nd if
If recordsearched = record(index) Then
found = True
Else
found = False
End If
If found = True Then
MsgBox "record found"
Else
index = index + 1
End If
'3rd if
If recordsearched = record(index) Then
found = True
Else
found = False
End If
If found = True Then
MsgBox "record found"
Else
index = index + 1
End If
'4th if
If recordsearched = record(index) Then
found = True
Else
found = False
End If
If found = True Then
MsgBox "record found"
Else
index = index + 1
End If
'5th if
If recordsearched = record(index) Then
found = True
Else
found = False
End If
If found = True Then
MsgBox "record found"
Else
index = index + 1
End If
'6th if
If recordsearched = record(index) Then
found = True
Else
found = False
End If
If found = True Then
MsgBox "record found"
Else
index = index + 1
End If
' 7th if
If recordsearched = record(index) Then
found = True
Else
found = False
End If
If found = True Then
MsgBox "record found"
Else
index = index + 1
End If
'8th if
If recordsearched = record(index) Then
found = True
Else
found = False
End If
If found = True Then
MsgBox "record found"
Else
index = index + 1
End If
'9th if
If recordsearched = record(index) Then
found = True
Else
found = False
End If
If found = True Then
MsgBox "record found"
Else
index = index + 1
End If
'10th if
If recordsearched = record(index) Then
found = True
Else
found = False
End If
If found = True Then
MsgBox "record found"
Else
MsgBox "record not found"
End If
End Sub
now dont get me wrong, this works but it wouldnt be practical if the shop had thousands of records (atm im testing with an array of only 10 records). im sure someone could help me
thanks for looking
Edited by - eyeball on 2/9/2005 3:29:30 PM
Updating Row Using ADO - Is There A More Efficient Way?
How can I update 1 row with a unique ID without having to actucally creat an SQL statement? I usually use something like the code below....where user enters a text in a forms textbox...and the text of the textbox is used to build an sql string.....but there must be a more efficient way:
Code:
On Error GoTo ErrTrap
Dim sql1 As String 'sql statement
Dim sql2 As String 'sql statement
Dim lstr As String 'String that contains record data
Dim cnSess As ADODB.Connection 'ADO Connection Object
Dim errLoop As ADODB.Error 'ADO Error object
Dim strError As String
'MS ACCESS DB........................................................................
Set cnSess = New ADODB.Connection
With cnSess
.Provider = "Microsoft.JET.OLEDB.4.0"
.ConnectionString = "database.mdb"
.Open
End With
'SQL STRING
sql1 = "UPDATE TABLE1 SET FIELD1 = '" & TextBox1.Text & "' WHERE ID = 1"
'EXECUTE UPDTE
cnSess.Execute (sql1)
Edited by - pbeast on 11/27/2007 9:15:03 AM
Efficient Collision Detection
I'm working on an RTS kind of game. When I get lots of multiple units moving at the same time, it runs slow. Right now I have the timer ticking 24 times a seond to move things, and I would like to keep it that fast because it looks better. My collision detection consists of a for loop that checks every other unit and makes sure the current one isn't moving onto it, and I think that's the major thing slowing it down. Is there a more efficient way to do this?
(by the way, I'm actually using .NET but I didn't notice there were separate places to post and I don't know how to move this)
Efficient Way To Draw Tiles
Hi, I need some suggestions to a tile engine... Now, for me, every time the map is scrolled, the whole thing is redrawn. Is this the only way? I tried to draw only the new stuff but... uh... failed horribly. Could anybody suggest a more efficient way (if there is one)? Thx
Making A Game More Efficient?
I have a strange thought that my game is probably very inefficient.
Is programming in direct X totally different than programming in Visual Basic? What are the advantages of programming in directX?
Is it better to program games in directX rather than visual basic?
I apologize if these question seems too elementary, but I am still fairly new to making games.
Thanks!
More Efficient 'battle System'
I am in process of writing a 2D strategy game, and I'd like to have many many 'dots' fight each other. Now the problem is that when i have 100 dots fighting in 2 teams, I get quite some lag... The way i do it right now is
Loop Every soldier
Loop Every soldier
Calculate the distance between these two soldiers
If distance is small, (he is in range)
attack him
End loop
End loop
So my code is n^2 efficiency, so 100 soldiers means 10 000 calculations. Is there any way you guys can think of which can help me to bypass this problem? Im sure the game developers have a better way of doing this... for example in Rome Total War you can have Tens of thousands of soldiers, and they have a great landscape and graphics, I only have dots.
Any suggestions?
Efficient 'close' Algorythm
I'm looking for an algorythm to quickly determine what the closest object to another object is in 2 dimensional space.
Right now I have a network of quad-nodes that link all the objects from left to right and top to bottom (I can insert all the objects in O(n log(n)) time or even O(n) using bucket sort). I keep the links up to date as things move around, ensuring the order isn't broken. When I want to find the closest I simply move right/left/up/down from the current ship, shrinking the maximum distance a ship can be away until I'm past that and then stop.
I'm not sure what the time complexity of it is (it depends on the random distrubtion of the minimum value of 4 random distributions...) but I'm sure it's better than "go through all the objects and check for each one, storing the minimum"
I just wanted to know what the popular algorythms are? My 'universe' is not limited (except by the max value of a long) so I'm not sure how that would work for quad-tree searches (massive amounts of memory).
|