473,545 Members | 2,095 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading values from a textbox

Greetings all,

I'm working on a program that allows a user to enter notes in a
multiline textbox. I would like to be able to read the contents of
the textbox (as records - one per line) and store in an array then a
file.

Perhaps this is the wrong control to use as there seems no way of
referencing each line of the text box.

Therefore my question is this: What is the best control to use that
will allow a user to enter one of more lines of text in a form then
write away to a file afterwards.

Apologies if this is a noddy question - too long using VAX-BASIC. :-)

Dave.
Jul 17 '05 #1
6 16854
On Tue, 19 Aug 2003 12:44:34 +0100, David Gray <po****@spamcop .net>
wrote:
Greetings all,

I'm working on a program that allows a user to enter notes in a
multiline textbox. I would like to be able to read the contents of
the textbox (as records - one per line) and store in an array then a
file.

Perhaps this is the wrong control to use as there seems no way of
referencing each line of the text box.

Therefore my question is this: What is the best control to use that
will allow a user to enter one of more lines of text in a form then
write away to a file afterwards.


It is quite possible to get individual lines from a Multi-Line Textbox

Whether it is the right control is another matter

Here is how to get the Lines - another example follows this :-

Option Explicit
' Add one Textbox
' Set it to MultiLine

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

Private Declare Function SendMessageStr Lib _
"user32" Alias "SendMessag eA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As String) As Long

Private Const EM_GETLINECOUNT = &HBA
Private Const EM_GETLINE = &HC4
Private Const EM_LINELENGTH = &HC1
Private Const EM_LINEINDEX = &HBB
Private Sub Command1_Click( )
Dim Lines&, S$, P&, L&
Const LINE_NO = 2

' --- Count the Lines
Lines& = SendMessage(Tex t1.hwnd, _
EM_GETLINECOUNT , _
0, _
0)
Me.Print Lines
' Note: If Text1.Text = "" then 1 is returned

' --- Now get position of start of 2nd line
' this is zero based
P& = SendMessage(Tex t1.hwnd, _
EM_LINEINDEX, _
LINE_NO - 1, _
0)
Me.Print "Line 2 Starts at:"; P
' --- Now Get its Length
L& = SendMessage(Tex t1.hwnd, _
EM_LINELENGTH, _
P, _
0)
Me.Print "Length of Line 2 is:"; L
' --- Now Get Line 2
S$ = Space$(L)
L& = SendMessageStr( Text1.hwnd, _
EM_GETLINE, _
LINE_NO - 1, _
S)
Me.Print S$
' --- And to prove it
Me.Print Mid$(Text1.Text , P + 1, L)

End Sub

========== END OF FIRST SAMPLE ============

This puts a Textbox over a Listbox
- it is also not ideal, but may give you some ideas

IMO one is far better off creating UserControls out of the simpler
Controls, rather than using more complex things that invariably behave
in a way that is not quite what one wants.

Option Explicit

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

Private Const LB_GETITEMRECT = &H198

Private Const LB_ERR = -1

Private Type TRECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Sub Form_Load()
Dim L9%

List1.Font.Size = 10
For L9 = 1 To 20
List1.AddItem "This is item" + Str$(L9)
Next
Text1.ZOrder vbBringToFront
Call MoveBox
End Sub

Private Sub List1_Click()
Call MoveBox
End Sub

Private Sub List1_Scroll()
Call MoveBox
End Sub
Private Sub MoveBox()
Dim Rect As TRECT, Q&

If List1.ListIndex < 0 Then
Text1.Visible = False
Exit Sub
End If

Q = SendMessage(Lis t1.hwnd, LB_GETITEMRECT, _
List1.ListIndex , Rect)
If Q = LB_ERR Then
Text1.Visible = False
Exit Sub
End If

Text1.Top = List1.Top + Rect.Top _
* Screen.TwipsPer PixelY
Text1.Left = List1.Left + Rect.Left _
* Screen.TwipsPer PixelX
Text1.Width = (Rect.Right - Rect.Left + 2) _
* Screen.TwipsPer PixelX
Text1.Height = (Rect.Bottom - Rect.Top + 1) _
* Screen.TwipsPer PixelY
Text1.Text = List1.List(List 1.ListIndex)

Text1.Visible = True
' note height of Textboxes
' is auto adjusted by windows
End Sub
Jul 17 '05 #2
> I'm working on a program that allows a user to enter notes in a
multiline textbox. I would like to be able to read the contents of
the textbox (as records - one per line) and store in an array then a
file.

Perhaps this is the wrong control to use as there seems no way of
referencing each line of the text box.

Therefore my question is this: What is the best control to use that
will allow a user to enter one of more lines of text in a form then
write away to a file afterwards.

Apologies if this is a noddy question - too long using VAX-BASIC. :-)


I'm a little unclear as to what your question is actually asking... Each
note can span more than one display line (that is, each note can wrap its
text), right? Are you trying to read each **displayed** line of text
individually (whether that is a full sentence/paragraph or not)? Or are you
trying to read each sentence (no matter how many display lines to
encompasses)? Or are you trying to read each individual paragraph (which I
assume are separated from each other by a blank line (produced by hitting
the Enter Key twice)?

Rick - MVP
Jul 17 '05 #3
David Gray wrote:
Greetings all,

I'm working on a program that allows a user to enter notes in a
multiline textbox. I would like to be able to read the contents of
the textbox (as records - one per line) and store in an array then a
file.

Perhaps this is the wrong control to use as there seems no way of
referencing each line of the text box.

Therefore my question is this: What is the best control to use that
will allow a user to enter one of more lines of text in a form then
write away to a file afterwards.

Apologies if this is a noddy question - too long using VAX-BASIC. :-)

Dave.


Text-control is fine...

But consider text-wrapping (like Rick Rothstein said).
Anyway: to check for individual lines in textbox: check for
chr(13)+chr(10) . Or was it chr(10)+chr(13) ? Or just chr(10)
or just chr(13)..... Don't know anymore ;-)

Homework 'How to figure this out?':
Create a text-control, write some text in it (make sure it
wraps around) Enter a Following line or two which don't wrap.
Read out the text-control-value and see what characters (like
chr(13), chr(10), chr(10)+chr(13) or chr(13)+chr(10) ) are used
to seperate the lines.....

Cookie

Jul 17 '05 #4
Dude

Use split :)

Take Care

Dim lines() As String

lines = Split(Text1, vbCrLf)
MsgBox lines(0)
MsgBox lines(1)


"David Gray" <po****@spamcop .net> wrote in message
news:cn******** *************** *********@4ax.c om...
Greetings all,

I'm working on a program that allows a user to enter notes in a
multiline textbox. I would like to be able to read the contents of
the textbox (as records - one per line) and store in an array then a
file.

Perhaps this is the wrong control to use as there seems no way of
referencing each line of the text box.

Therefore my question is this: What is the best control to use that
will allow a user to enter one of more lines of text in a form then
write away to a file afterwards.

Apologies if this is a noddy question - too long using VAX-BASIC. :-)

Dave.

Jul 17 '05 #5
> Each note can contain multiple sentences and paragraphs, blank lines
may also be present. I don't care about the whether a sentence spans
multiple lines, I just need to put each line into an array so I can
dump it to a file.
You still didn't make it clear whether you wanted to preserve the
**displayed** line structure or not. That is, did you want to preserve the
line wrapping exactly as seen on the screen or not?
Alternatively can I just dump the entire contents of a text box to a
file?


This question makes it seem like you don't want the **displayed** line
structure, only the sentence/paragraph structure. Assuming that, you just
want to save out the Text property of the TextBox (assumed to be named Text1
for this example). Something like this.

Dim FF As Long
Dim FileName As String
FileName = <<Put Name Of Storage File Here>>
FF = FreeFile
Open FileName For Output As #FF
Print #FF, Text1.Text
Close #FF

The above creates a new file using the name you provide in the FileName
variable above: OR completely overwrite an existing file, if any, that has
that same name (thus, you would lose its contents). If there is an existing
file by that same name, and if you want to append the contents of the
TextBox onto instead, use this Open statement instead of the one above (and
leave the other lines as is).

Open FileName For Append As #FF

Rick - MVP
Jul 17 '05 #6
Create a loop that looks for the return character then extracts the
information prior to that. Line 1,
Do it again until no more returns are found. Ta da.. all in separate lines.

Private Sub BreakLine()
Dim txtBox As String
Dim txtLines() As String
Dim lngLines As Long
Dim lngCrlf As Long
lngStart = 1
txtBox = Text1

Do While InStr(1, txtBox, vbCr) <> 0
ReDim Preserve txtLines(lngLin es)
lngCrlf = InStr(1, txtBox, vbCrLf)
txtLines(lngLin es) = Left(txtBox, lngCrlf - 1)
txtBox = Mid(txtBox, lngCrlf + 2, Len(txtBox) - lngCrlf)
' You need to add 2 to the carriage return because a blank space is in there
for some reason.
lngLines = lngLines + 1
Loop

End Sub
Suzette

"Cookie" <co****@yucom.b e> wrote in message
news:3F******** ******@yucom.be ...
David Gray wrote:
Greetings all,

I'm working on a program that allows a user to enter notes in a
multiline textbox. I would like to be able to read the contents of
the textbox (as records - one per line) and store in an array then a
file.

Perhaps this is the wrong control to use as there seems no way of
referencing each line of the text box.

Therefore my question is this: What is the best control to use that
will allow a user to enter one of more lines of text in a form then
write away to a file afterwards.

Apologies if this is a noddy question - too long using VAX-BASIC. :-)

Dave.


Text-control is fine...

But consider text-wrapping (like Rick Rothstein said).
Anyway: to check for individual lines in textbox: check for
chr(13)+chr(10) . Or was it chr(10)+chr(13) ? Or just chr(10)
or just chr(13)..... Don't know anymore ;-)

Homework 'How to figure this out?':
Create a text-control, write some text in it (make sure it
wraps around) Enter a Following line or two which don't wrap.
Read out the text-control-value and see what characters (like
chr(13), chr(10), chr(10)+chr(13) or chr(13)+chr(10) ) are used
to seperate the lines.....

Cookie

Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
12709
by: Suresh Kumaran | last post by:
Hi All, Does anybody know the sytax in VB.NET to write the contents of a multiline text box to a text file? Appreciate help. Suresh
5
6919
by: Robert Phillips | last post by:
I have a Panel control containing a few TextBox controls. The Panel is originally enabled, I enter data into the TextBox controls. When I submit, the Panel is disabled during the PostBack and the TextBox controls render greyed-out, and I can see the values in the TextBox controls....this is what I expected. I submit again, the Panel is...
0
1801
by: Newasps | last post by:
Hi guys, I have a problem with UpdateCommand Event. In tihs event Ä°'m creating required controls to get that controls' values and also get them. But when I try to get updated values I'm getting the first values for each control. Please help me. Thanks for any help. Bye Ozer And here's my code: Imports System Imports System.Data...
4
8751
by: bwalke | last post by:
I am developing a web form which is going to be used for manufacturing input. The form uses a DataList which list a batch of parts that may range anywhere from 1-9 parts. The DataList contains 6 textboxes pre-fill with data (reason for using datalist) which will capture user input and changes to the textboxes. So the 6 textboxes in columns...
2
1685
by: Kiran Kumar Pinjala | last post by:
Hi, May be this is silly, or I just need a second pair eyes to look at this. I am trying to get values that I have edited in a datagrid and update the values with those values. Here is the code that I am using in my update command. TextBox txtProdName = (TextBox)e.Item.Cells.Controls; TextBox txtSuppID = (TextBox)e.Item.Cells.Controls;...
1
1219
by: KasperBirch | last post by:
Hi NG Im trying to read the values of a bunch of TextBox'es that I add in a loop, dynamically. The page has an <asp:Table id="table" ...> control, and I add rows with textboxes like this (from memory, never mind syntax): for (int i = 0; i<10; i++) {
7
2591
by: Nez | last post by:
Help needed! Hello, I have looked everywhere for a solution to my problem and this is pretty much my last resource. I have created a table in a span with the innerhtml command in my code behind. In this table I have created textbox html input fields. Now I need to allow the user to change the value in the textfield, and compare it to the...
0
2389
by: Mike Collins | last post by:
I someone can please help, I am about at an end in trying to figure this out. I am adding some dynamic controls to my page (I found out that I was supposed to be doing that in the oninit event, which I am). I now want to read the text/values of those controls. I have found out that I can read the values if I wait until Page_Load, but then I...
4
8541
by: pankajsingh5k | last post by:
Hi guys, These question is for all the experts... Please help me before my brain explodes The problem is again with the formview control.. I have a formview and i have to use it that when it displays it shows values from the database and i have a link button edit on the ItemTemplate that changes the mode to edit mode and allows to...
0
7396
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7656
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7805
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7413
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5323
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4943
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3449
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1874
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.