Re: Clearing Variables
- From: "Cor Ligthert[MVP]" <Notmyfirstname@xxxxxxxxx>
- Date: Sat, 1 Nov 2008 10:22:51 +0100
Larry,
I am busy with VB6 you should have seen it, it seems that I remember much but not all, it has cost me yesterday almost two hour to remember what was the code to find something in a string. I found it by using a message I wrote in 2002 in the dotNet newsgroup. That was about a test I made what was the quickest in VB for Net to find something in a string (The quickest was Instr) . Although the Instr is a member in .Net, it was almost not to find on MSDN.
However, my question. That original code that the OP shows is that possible in versions before .Net? Because then I can use it.
As it is for .Net then there is a better method than as I have seen given here, I have the idea that some answers are VB for Net, but as the OP want that better method for versions newer than VB6, he would put his question in the newsgroup microsoft.dotnet.languages.vb
Cor
"Larry Serflaten" <serflaten@xxxxxxxxxxxxxx> wrote in message news:%23PKOmxsOJHA.200@xxxxxxxxxxxxxxxxxxxxxxx
"LondonLad" <LondonLad@xxxxxxxxxxxxxxxxxxxxxxxxx> wroteHi Larry
They are all the same type's in each group mostly strings, I use for printing
each group consists of 8 vars and as I can print up to 6 block wide this
means 48 vars in total, each group has a number to show which block I am
looking at in the event of an error.
example:-
Because you are managing all string data, you might take a third route
and provide one big string buffer to hold all the data for the duration of
your print process. That would eliminate the constant creation and
destruction of the various strings. For an example, paste the code
below in a standard Module, and use it like:
' Assign (field #, line #)
FieldLine(1, 1) = "Hello"
FieldLine(2, 1) = "World"
' See
Debug.Print FieldLine(1, 1), FieldLine(2, 1)
' Erase
ClearLine 1
' See
Debug.Print FieldLine(1, 1), FieldLine(2, 1)
You could use shorter names for easier typing, but the idea is
that you pass in indexes to a property to both assign and
retrieve the string data. Included in the module is the means to
erase an entire line, or the whole buffer (ClearXXX methods).
See if that will suit your needs....
LFS
--- Module code ---
Option Explicit
Const FieldCount As Long = 8 ' 0 - 7
Const LineCount As Long = 6 ' 0 - 5
Const FieldSize As Long = 10 ' 10 characters max (all fields)
Const LineSize As Long = FieldSize * FieldCount
Private PrintData As String
Public Sub ClearLine(ByVal LineNumber As Long)
Dim pos As Long
' Init line
pos = DataOffset(0, LineNumber)
Mid(PrintData, pos, LineSize) = Space$(LineSize)
End Sub
Public Sub ClearData()
' Init all
PrintData = Space$(LineSize * LineCount + 1)
End Sub
Public Property Get FieldLine(ByVal FieldPosition As Long, ByVal LineNumber As Long) As String
Dim pos As Long
' Returns data
pos = DataOffset(FieldPosition, LineNumber)
FieldLine = RTrim$(Mid$(PrintData, pos, FieldSize))
End Property
Public Property Let FieldLine(ByVal FieldPosition As Long, ByVal LineNumber As Long, Value As String)
Dim pos As Long
' Assigns data
pos = DataOffset(FieldPosition, LineNumber)
' Init data if needed
If Len(PrintData) < (pos + FieldSize) Then
PrintData = Left$(PrintData & Space$(LineSize * LineCount + 1), LineSize * LineCount + 1)
End If
Mid(PrintData, pos, FieldSize) = Left$(Value & Space$(FieldSize), FieldSize)
End Property
Private Function DataOffset(Field As Long, Line As Long) As Long
' Field/Line value validation & offset calculation
If (Field < 0) Or (Field >= FieldCount) Or (Line < 0) Or (Line >= LineCount) Then
Err.Raise 5 ' Invalid call (check call stack)
Else
DataOffset = (LineSize * Line) + (FieldSize * Field) + 1
End If
End Function
.
- Follow-Ups:
- Re: Clearing Variables
- From: Larry Serflaten
- Re: Clearing Variables
- Prev by Date: StrComp (vbTextCompare) out of order!
- Next by Date: Re: Preventing a crash
- Previous by thread: Re: Clearing Variables
- Next by thread: Re: Clearing Variables
- Index(es):
Relevant Pages
|