my text box have multi lines i want to count those lines and show it in form caption.
spoz i have 12 lines in text1.text i want show it like this
1 Textbox, 1 Button. Result showing in form caption :
Private Sub Command1_Click() Dim TextLines As Variant TextLines = Split(Text1, vbNewLine) Form1.Caption = "Sockz-" & (UBound(TextLines) + 1) End Sub
That's fine, as long as you have explicit line breaks on every line in your text.
If you have a multi-line text box without horizontal scroll (a.k.a. "Word Wrap"), it gets way more complicated. You have to use some Windows function calls to get the text metrics for your textbox, use the average character width and height values to calculate how wide a given line is to figure out how many lines you have for the font that your text box is using. Not for the faint of heart.
However, at the risk of making things WAY worse, there is a handy control called a "RichTextBox" that implements a method "GetLineFromChar". You can put a RichTextBox control (hidden, of course) with the same dimensions as your text box on your form, copy your text into the hidden RichTextBox, then use that method to get the line number you need. Then your code would look like this:
Private Sub Command2_Click() Dim x As Integer Me.RichTextBox1.Text = Me.Text1.Text x = Me.RichTextBox1.GetLineFromChar(Len(Me.RichTextBox1.Text)) + 1 Form1.Caption = "Sockz-" & Str(x) End Sub
Granted, it's not pretty, and it does require an extra component when you deploy, but it works.
Oh, and by the way...the GetLineFromChar starts counting from line 0 (that's why you have to add 1).
Hope this is more useful than ugly. Good luck!
i never found a site good for new learners like me like this site, thank you
Edited 4 Years Ago by honeybee2090
OK, so HostGator for some reason no longer allows gcc/g++ access unless you have a Designated Server account, which is a lot of money to spend just to compile my "Hello World" program. Thus I figured I'd compile at home, then upload. Program is your regular old bare-bones Hello World ...
Hi. I have a form with list box : lst_product, datagridview : grd_order and button: btn_addline. lst_product has a list of product ids selected from database (MS Acess 2013) , grd_order is by default empty except for 2 headers and btn_addline adds rows to grd_order.
Private Sub btn_addline_Click(ByVal ...
Hi, as I was told that my code doesn’t scale well at all, I thought perhaps I’d try to get a better understanding of interfaces/abstract classes and classes and the relationship between them.
I don’t want at this stage work on a big separate project as I've already got plenty ...