Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.89/5 (3 votes)
See more:
I am developing cheque printing software, so some banks have payee row in line1 and payee line2 in row2. I am trying to put payee text into both text boxes from dropdown control selected payee to I,e txtpayee1 and txtpayee2.

[EDIT OP code from comment]
Below is the method that I am trying, what is my motto is combobox selected text display into two textboxes I,e in first textbox will print only 10 characters remaining display into 2textbox.
VB
Public Sub Addpayee2()
    Try
       Dim payee2 As String = ""
       payee2 = cboAccounts.Text.ToString()

       Dim g As Graphics = cboAccounts.CreateGraphics
       Dim payee2word As String, oneLine As String
       Dim test As String = "", test1 As String = ""
       Dim p2words() As String

       If g.MeasureString(payee2, txtPayAgainst.Font).Width >= txtPayAgainst.Width Then
           oneLine = payee2
           p2words = oneLine.Split(" ")
           For Each word In p2words
               test = test & word
               If g.MeasureString(test, txtPayAgainst.Font).Width >= txtPayAgainst.Width Then
                   txtPayAgainst.Text = test1
                   GoTo l1
               Else
                   test = test & " "
                   test1 = test
               End If
           Next
l1:        txtPayAgainst.Text = test1
           txtpayee2.Text = payee2.Substring(test1.Length)
       Else
           txtPayAgainst.Text = payee2
           txtpayee2.Text = ""
       End If

    Catch ex As Exception
        MsgBox(ex.Message, , "Cheque Print")
    End Try

 End Sub
Posted
Updated 9-Jun-15 0:09am
v2
Comments
CHill60 9-Jun-15 3:46am    
You've told us what you are trying to do, but not how you are doing it, nor what is going wrong.
Share the code you have tried so far and explain what the problem is
Meer Wajeed Ali 9-Jun-15 6:05am    
Below is the method that I am trying, what is my motto is combobox selected text display into two textboxes I,e in first textbox will print only 10 characters remaining display into 2textbox.
Public Sub Addpayee2()
Try
Dim payee2 As String = ""
payee2 = cboAccounts.Text.ToString()

Dim g As Graphics = cboAccounts.CreateGraphics
Dim payee2word As String, oneLine As String
Dim test As String = "", test1 As String = ""
Dim p2words() As String

If g.MeasureString(payee2, txtPayAgainst.Font).Width >= txtPayAgainst.Width Then
oneLine = payee2
p2words = oneLine.Split(" ")
For Each word In p2words
test = test & word
If g.MeasureString(test, txtPayAgainst.Font).Width >= txtPayAgainst.Width Then
txtPayAgainst.Text = test1
GoTo l1
Else
test = test & " "
test1 = test
End If
Next

l1: txtPayAgainst.Text = test1
txtpayee2.Text = payee2.Substring(test1.Length)
Else
txtPayAgainst.Text = payee2
txtpayee2.Text = ""
End If

Catch ex As Exception
MsgBox(ex.Message, , "Cheque Print")
End Try

End Sub
CHill60 9-Jun-15 6:16am    
This essentially works, except that it is calculating whether or not it can display each word in the width of the textbox, rather than truncating at 10 characters (which is strange requirement anyway).
Word of advice - get rid of that GoTo l1 and replace it with Exit For
Ralf Meier 9-Jun-15 3:47am    
I don't understand what you mean.
Perhaps you give an example for what you have and what you want to get ...

1 solution

Your starting line si almost right,
VB
Dim payee2 As String = cboAccounts.Text

Then use the Length property, it shows you the number of characters in the string (do not use the MeasureString functions - they are used to get the number of pixels for the string with a given font etc.).
If it's too long, make use of the SubString function:
VB
txtPayAgainst.Text = payee2.Substring(0, 10)
txtpayee2.Text = payee2.Substring(10)
 
Share this answer
 
Comments
Meer Wajeed Ali 9-Jun-15 8:45am    
thx for the support. But didn't getting values into txtpayee2. I want to assign only 10 characters from combobox into txtpayagain and remaining text assign into txtpayee2.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900