Re: Clearing Variables

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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> wrote
Hi 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





.



Relevant Pages

  • Re: Clearing Variables
    ... Because you are managing all string data, you might take a third route ... Public Sub ClearLine(ByVal LineNumber As Long) ... Dim pos As Long ... FieldLine = RTrim$(Mid$(PrintData, pos, FieldSize)) ...
    (microsoft.public.vb.general.discussion)
  • Re: Dynamic text color
    ... I was changing the line-column index to a FLOAT because the search would return the starting position of the string, then by making it a FLOAT and adding the string length I was able to get the end position. ...
    (comp.lang.python)
  • Re: Open Sound Control
    ... \0s at the end of the string to pad it to a 32bit boundary. ... puts [string length $packet] ... instead it extracts both the I* and R* lists once ... set len [lindex $l $pos] ...
    (comp.lang.tcl)
  • FAQ 6.19 What good is "G" in a regular expression?
    ... any characters to find the next match with this anchor, ... It uses the value of pos() as the ... Each string has its own posvalue. ... After the match fails at the letter "a", perl resets pos() and the next ...
    (comp.lang.perl.misc)
  • FAQ 6.19 What good is "G" in a regular expression?
    ... any characters to find the next match with this anchor, ... It uses the value of pos() as the ... Each string has its own posvalue. ... After the match fails at the letter "a", perl resets pos() and the next ...
    (comp.lang.perl.misc)