?
Solved

How to read textbox with multiple lines separated by slushes?

Posted on 2011-09-26
8
Medium Priority
?
242 Views
Last Modified: 2012-05-12
I have a textbox name text1.text. It has a multiple text. Each line are separated with slushes till the last  line. here's the data of the textbox;

3356\Paracetamol 500mg\30
123490\Amoxicillin 350mg Cap\25
7685\Cefalexin\90

I want to read the first line each data separated by "\" till the last line. How? Pls...
0
Comment
Question by:Whing Dela Cruz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 16

Assisted Solution

by:HooKooDooKu
HooKooDooKu earned 400 total points
ID: 36601686
What exactly do you mean "read"?

If the textbox is a multiline text box, then the entire contents of the textbox is actually a single string of text, with Carriage-Return/Line-Feed pairs denoting where the lines seperate (not sure, but a simple Carriage-Return by itself might also be able to denote the end of the line).

So one solution might be to so a simple string replace to convert the '\' to Carriage-Return/Line-Feed pairs, then use Instr() to find the Carriage-Return/Line-Feed pairs.

Dim A$(100)
Dim str as String
Din
str = Text1.text
Replace( str, "/", vbCrLf )
Dim Count as integer
Dim I as integer
Dim Last as integer

Last = 1
I = InStr( str, vbCrLf )
do while( I > 0 )
    Count = Count + 1
    A$(Count) = Mid$(str, Last, I - Last)
    Last = I + 2
    I = Instr( Last, str, vbCrLf )
loop
0
 
LVL 76

Assisted Solution

by:GrahamSkan
GrahamSkan earned 1600 total points
ID: 36601744
You could do it like this:

Private Sub Command1_Click()
Dim strlines() As String
    Dim strItems() As String
    Dim l As Integer
    Dim I As Integer
    strlines = Split(Me.Text1.Text, vbCrLf)
    For l = 0 To 2
        strItems() = Split(strlines(l), "\")
        For I = 0 To 2
            Debug.Print l, I, strItems(I)
        Next I
    Next l
End Sub

Open in new window

0
 

Author Comment

by:Whing Dela Cruz
ID: 36601942
Hi HooKooDooKu,
 What I mean about read is;
msgbox first line 'read the first line each data separated by "\" and able to loop till the last line.  
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 76

Expert Comment

by:GrahamSkan
ID: 36602171
Does my code suit you? I don't know what you want to do with the data, so I just show it in the Immediate window.
0
 

Author Comment

by:Whing Dela Cruz
ID: 36602210
GrahamSkan, you got exactly what I need, Thanks a lot.. Could i ask more question? I need more help about the things I've trying to develop.  it is textbox to excell. Thru your help i was able develop the code below, but the problem is.. it only save one data, the last data of the textbox...
Private Sub Command1_Click()
   Dim oExcel As Object
   Dim oBook As Object
   Dim oSheet As Object

   'Start a new workbook in Excel
   Set oExcel = CreateObject("Excel.Application")
   Set oBook = oExcel.Workbooks.Add
   
   'Add data to cells of the first worksheet in the new workbook
   Set oSheet = oBook.Worksheets(1)
   oSheet.range("A1").Value = "Code"
   oSheet.range("B1").Value = "Description"
   oSheet.range("c1").Value = "Quantity"
   oSheet.range("A1:B1:C1").Font.Bold = True

Dim strlines() As String
    Dim strItems() As String
    Dim l As Integer
    Dim I As Integer
    strlines = Split(Me.Text1.Text, vbCrLf)
    For l = 0 To 2
        strItems() = Split(strlines(l), "\")
        For I = 0 To 2
        Next I
            oSheet.range("A2").Value = strItems(0)
            oSheet.range("B2").Value = strItems(1)
            oSheet.range("C2").Value = strItems(2)
            
    Next l

   'Save the Workbook and Quit Excel
   oBook.SaveAs "C:\Report.xlsx"
   oExcel.Quit
   
End Sub

Open in new window

0
 
LVL 76

Assisted Solution

by:GrahamSkan
GrahamSkan earned 1600 total points
ID: 36602324
A couple of problems.

The For/Next loop lines 24 and 25 does nothing, and the lines 26 to 25 do not vary the row. Try this. (I've changed the variable I to c, because I looks a bit like l
Dim oExcel As Object
   Dim oBook As Object
   Dim oSheet As Object

   'Start a new workbook in Excel
   Set oExcel = CreateObject("Excel.Application")
   Set oBook = oExcel.Workbooks.Add
   oExcel.Visible = True
   'Add data to cells of the first worksheet in the new workbook
   Set oSheet = oBook.Worksheets(1)
   oSheet.range("A1").Value = "Code"
   oSheet.range("B1").Value = "Description"
   oSheet.range("c1").Value = "Quantity"
   oSheet.range("A1:B1:C1").Font.Bold = True

Dim strlines() As String
    Dim strItems() As String
    Dim l As Integer
    Dim c As Integer
    strlines = Split(Me.Text1.Text, vbCrLf)
    For l = 0 To 2
        strItems() = Split(strlines(l), "\")
        For c = 0 To 2
            oSheet.Cells(l + 2, c + 1).Value = strItems(c)
         Next c
           
    Next l

   'Save the Workbook and Quit Excel
   oBook.SaveAs "C:\Report.xlsx"
   oExcel.Quit

Open in new window

0
 

Accepted Solution

by:
Whing Dela Cruz earned 0 total points
ID: 36602375
Thanks a lot GrahamSkan, its really working... More Power to you! and God Bless!
0
 

Author Closing Comment

by:Whing Dela Cruz
ID: 36895909
Thank you so much... excellent solution...
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question