Click to See Complete Forum and Search --> : need these two functions (in text box)


ma622
August 14th, 2001, 01:39 PM
i need two functions:

1. function that will put # line to # variable
for example the text is:

hello
my nick is ma622

so i want it:
function(2,nick)-----it will put "my nick is ma622" to the variable "ma622"
2. function that will count how much lines in the text box

10X

John G Duffy
August 14th, 2001, 08:20 PM
You can't create variables at run time. Your best bet is to use Collections making "ma622" as the key to an element and the "my nick is ma622" as the text. You can then retrieve the information using the key value. Here is a real simple sample of adding data to a collection and retrieving it. This sample, uses hard coded data. You can of course use variables to input the data.
Add two command buttons to a form and paste this code into the general declaration section of the form. Run it. Click command1 which creates a collection element. Click command2. It will display what was just created.

option Explicit
Dim MyCol as Collection
Dim Zipcode as Integer
private Sub Command1_Click()
' Add a Zipcode to the collection
MyCol.Add "City,State", CStr(Zipcode)

End Sub

private Sub Command2_Click()
' Retrieve a zipcodes city and state
MsgBox MyCol.Item(CStr(Zipcode))

End Sub

private Sub Form_Load()
' Establish new colection
set MyCol = new Collection
Zipcode = 29483
End Sub




John G

Iouri
August 15th, 2001, 07:16 AM
'THis function will return quantity of the lines in the textbox

Private Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long

Const EM_GETLINECOUNT = &HBA



'Call API to determine how many lines of text are in text box
LinesOfText = SendMessage(Text1.hwnd, EM_GETLINECOUNT, 0&, 0&)


Iouri Boutchkine
iouri@hotsheet.com

Iouri
August 15th, 2001, 07:18 AM
'another way to calculat elines in a textbox
lineCount = Len(Text1.Text) - Len(Replace(Text1.Text, vbCrLf, vbCr))

Iouri Boutchkine
iouri@hotsheet.com

Iouri
August 15th, 2001, 07:20 AM
In order to put a certain line from the text box to the variable, try to read text from the textbox between vbCrLf and when you find the desired text assign it to a variable

I hope that what you want

Iouri Boutchkine
iouri@hotsheet.com

RobZeilinga
August 16th, 2001, 07:51 AM
'Here is something I ran across.
'I did not write it.
'Start a new Project, Add a Module. Add a ComboBox, A command Button, two labels and a textBox
'using the default names to the form.



'http://www.vb-helper.com/HowTo/execline.zip
'PurposeExecute a line of code stored in a string
'MethodUse the EbExecuteLine API function.
'Thanks to Sergio Perciballi (oigres@postmaster.co.uk).
'DisclaimerThis example program is provided "as is" with no warranty of any kind. '
'It isintended for demonstration purposes only. In particular, it does no errorhandling.
'You can use the example in any form, but please mention
' www.vb-helper.com.

' Copy the following to a form



'------------------------------------------
' (c) 1999 Trigeminal Software, Inc. All Rights Reserved
'------------------------------------------
'Thanks to ----------michka - Michael Kaplan
'Rest of code by Sergio Perciballi -oigres P (Aug-6-2000)
'Email: oigres@postmaster.co.uk
'Uses the function used by the immediate window
'to execute a line of code.
option Compare Text
option Explicit
private Declare Function EbExecuteLine Lib "vba6.dll" _
(byval pStringToExec as Long, byval Foo1 as Long, _
byval Foo2 as Long, byval fCheckOnly as Long) as Long
' for VB5 IDE
'Declare Function EbExecuteLine Lib "vba5.dll" _
(byval pStringToExec as Long, byval Foo1 as Long, _
byval Foo2 as Long, byval fCheckOnly as Long) as Long
' for Access 97/VBE.dll clients like Word 97 and Excel 97
'Declare Function EbExecuteLine Lib "vba332.dll" _
(byval pStringToExec as Long, byval Foo1 as Long, _
byval Foo2 as Long, byval fCheckOnly as Long) as Long
Function FExecuteCode(stCode as string, optional fCheckOnly as Boolean) as Boolean

FExecuteCode = EbExecuteLine(StrPtr(stCode), 0&, 0&, Abs(fCheckOnly)) = 0
End Function
private Sub Combo1_Click()

Text1.Text = Combo1.List(Combo1.ListIndex)
End Sub
private Sub Command1_Click()

Dim res as Boolean
res = FExecuteCode(Text1.Text)
Label1.Caption = "Status = " & res
End Sub

private Sub Form_Click()
Form2.Show
End Sub

private Sub Form_Load()
Combo1.AddItem "?secret"
Combo1.AddItem "msgbox secret"
Combo1.AddItem "secret2"
Combo1.AddItem "for x=0 to 5:?" & Chr$(34) & "hello " & Chr$(34) & "&x:next:beep"
Combo1.AddItem "sendkeys " & Chr$(34) & "{TAB}" & Chr$(34) & ":sendkeys " & Chr$(34) & "{up}" & Chr$(34)
Combo1.AddItem "shell " & Chr$(34) & "calc.exe" & Chr$(34) & ",vbNormalFocus"
Combo1.AddItem "shell " & Chr$(34) & "c:\windows\explorer.exe ::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" & Chr$(34) & ",vbNormalFocus"
Combo1.AddItem "form1.text1.visible=false"
Combo1.AddItem "form1.text1.visible=true"
Combo1.AddItem "form1.combo1.listindex=1"
Combo1.AddItem "msgbox app.Title"
Combo1.AddItem "form1.combo1.listindex=1:form1.command1.value=true"
Combo1.ListIndex = 0
Show
End Sub




hope this helps
RobZ