Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting the new height of a textbox in CR(8) needed

Status
Not open for further replies.

dafi

Programmer
Apr 19, 2001
25
0
0
RO
I have a section in my report that needs to have at least 12 lines(graphically) drawn.

if the text that I superpose on the lines exceeds 12 lines I have to increase the number of drawn lines to create the "look".

Ex:
test test test ... .... ... test
---------------------------------------------------------
.
.
.
test test test ... .... ... test
---------------------------------------------------------
Let's say that I have now 14 lines drawn under the text.
The text can be as big as the input is and the length of each "row"(not a recorset row) is equal to the line's length.

Another Ex: my string is big enough to be shown on 3 rows(lines) so under every row I need to draw a line.

The problem is that I cannot get the height of the textbox which contains the input string.
I can draw lines as many I want but I have to know the exact number.
If is not possible to get the text height is it possible to get the section height ?

I have a terrible cold, and my mind is probably playing tricks on me so that I cannot find any solution to this small problem.

I cannot use a formatting of the font to underline the text because it is very possible to exists vbcrlf-s in the input string and it ruins everything


 
well, i've noticed that it was no answer for my question so I worked a little on the background and I've finnaly reached th solution.

The solution is based on having an array containing the length of each character for (in may case) Times 12.

How to do it ?
simply make a new form, set font to Times 12
and then use TextWidth function
You can also "generate" your array into an Richtextbox to be simplier.

When You have it all, you send to the function get_nr_rows the string and the maximum length allowed and it returns the number that you need.

So if your text needs underline you can use drawing lines at runtime.
For instance the gap between lines for a text formatted with Times New Roman 12 , the gap is 284.

and now is the script ... efficient
If you find particullary usefull this script don't forget to RATE IT .
Thanks and enjoy

Public Sub initializeaza_info()
lcar(0) = 180
lcar(1) = 180
lcar(2) = 180
lcar(3) = 180
lcar(4) = 180
lcar(5) = 180
lcar(6) = 180
lcar(7) = 180
lcar(8) = 180
lcar(9) = 720
lcar(10) = 0
lcar(11) = 180
lcar(12) = 180
lcar(13) = 0
lcar(14) = 180
lcar(15) = 180
lcar(16) = 180
lcar(17) = 180
lcar(18) = 180
lcar(19) = 180
lcar(20) = 180
lcar(21) = 180
lcar(22) = 180
lcar(23) = 180
lcar(24) = 180
lcar(25) = 180
lcar(26) = 180
lcar(27) = 180
lcar(28) = 180
lcar(29) = 180
lcar(30) = 180
lcar(31) = 180
lcar(32) = 60
lcar(33) = 75
lcar(34) = 75
lcar(35) = 120
lcar(36) = 120
lcar(37) = 195
lcar(38) = 180
lcar(39) = 45
lcar(40) = 75
lcar(41) = 75
lcar(42) = 120
lcar(43) = 135
lcar(44) = 60
lcar(45) = 90
lcar(46) = 60
lcar(47) = 60
lcar(48) = 120
lcar(49) = 120
lcar(50) = 120
lcar(51) = 120
lcar(52) = 120
lcar(53) = 120
lcar(54) = 120
lcar(55) = 120
lcar(56) = 120
lcar(57) = 120
lcar(58) = 45
lcar(59) = 60
lcar(60) = 135
lcar(61) = 135
lcar(62) = 135
lcar(63) = 105
lcar(64) = 225
lcar(65) = 165
lcar(66) = 150
lcar(67) = 165
lcar(68) = 165
lcar(69) = 135
lcar(70) = 135
lcar(71) = 165
lcar(72) = 165
lcar(73) = 75
lcar(74) = 90
lcar(75) = 180
lcar(76) = 135
lcar(77) = 210
lcar(78) = 180
lcar(79) = 180
lcar(80) = 135
lcar(81) = 180
lcar(82) = 150
lcar(83) = 135
lcar(84) = 135
lcar(85) = 165
lcar(86) = 165
lcar(87) = 225
lcar(88) = 165
lcar(89) = 165
lcar(90) = 135
lcar(91) = 75
lcar(92) = 60
lcar(93) = 75
lcar(94) = 120
lcar(95) = 120
lcar(96) = 75
lcar(97) = 105
lcar(98) = 120
lcar(99) = 105
lcar(100) = 120
lcar(101) = 105
lcar(102) = 60
lcar(103) = 105
lcar(104) = 105
lcar(105) = 45
lcar(106) = 60
lcar(107) = 120
lcar(108) = 45
lcar(109) = 165
lcar(110) = 105
lcar(111) = 120
lcar(112) = 120
lcar(113) = 120
lcar(114) = 75
lcar(115) = 90
lcar(116) = 60
lcar(117) = 105
lcar(118) = 105
lcar(119) = 165
lcar(120) = 105
lcar(121) = 105
lcar(122) = 90
lcar(123) = 105
lcar(124) = 45
lcar(125) = 120
lcar(126) = 135
lcar(127) = 180
lcar(128) = 120
lcar(129) = 180
lcar(130) = 75
lcar(131) = 120
lcar(132) = 90
lcar(133) = 240
lcar(134) = 120
lcar(135) = 105
lcar(136) = 75
lcar(137) = 240
lcar(138) = 135
lcar(139) = 75
lcar(140) = 210
lcar(141) = 180
lcar(142) = 135
lcar(143) = 180
lcar(144) = 180
lcar(145) = 75
lcar(146) = 75
lcar(147) = 90
lcar(148) = 90
lcar(149) = 90
lcar(150) = 120
lcar(151) = 240
lcar(152) = 75
lcar(153) = 240
lcar(154) = 90
lcar(155) = 75
lcar(156) = 165
lcar(157) = 180
lcar(158) = 90
lcar(159) = 165
lcar(160) = 60
lcar(161) = 75
lcar(162) = 120
lcar(163) = 120
lcar(164) = 120
lcar(165) = 120
lcar(166) = 45
lcar(167) = 120
lcar(168) = 75
lcar(169) = 180
lcar(170) = 75
lcar(171) = 105
lcar(172) = 135
lcar(173) = 90
lcar(174) = 180
lcar(175) = 120
lcar(176) = 90
lcar(177) = 135
lcar(178) = 75
lcar(179) = 75
lcar(180) = 75
lcar(181) = 105
lcar(182) = 105
lcar(183) = 60
lcar(184) = 60
lcar(185) = 75
lcar(186) = 75
lcar(187) = 105
lcar(188) = 180
lcar(189) = 180
lcar(190) = 180
lcar(191) = 105
lcar(192) = 165
lcar(193) = 165
lcar(194) = 165
lcar(195) = 165
lcar(196) = 165
lcar(197) = 165
lcar(198) = 195
lcar(199) = 165
lcar(200) = 135
lcar(201) = 135
lcar(202) = 135
lcar(203) = 135
lcar(204) = 75
lcar(205) = 75
lcar(206) = 75
lcar(207) = 75
lcar(208) = 165
lcar(209) = 180
lcar(210) = 180
lcar(211) = 180
lcar(212) = 180
lcar(213) = 180
lcar(214) = 180
lcar(215) = 135
lcar(216) = 180
lcar(217) = 165
lcar(218) = 165
lcar(219) = 165
lcar(220) = 165
lcar(221) = 165
lcar(222) = 150
lcar(223) = 120
lcar(224) = 105
lcar(225) = 105
lcar(226) = 105
lcar(227) = 105
lcar(228) = 105
lcar(229) = 105
lcar(230) = 165
lcar(231) = 105
lcar(232) = 105
lcar(233) = 105
lcar(234) = 105
lcar(235) = 105
lcar(236) = 45
lcar(237) = 45
lcar(238) = 45
lcar(239) = 45
lcar(240) = 120
lcar(241) = 105
lcar(242) = 120
lcar(243) = 120
lcar(244) = 120
lcar(245) = 120
lcar(246) = 120
lcar(247) = 135
lcar(248) = 120
lcar(249) = 105
lcar(250) = 105
lcar(251) = 105
lcar(252) = 105
lcar(253) = 105
lcar(254) = 120
lcar(255) = 105


End Sub

Function get_width(i As Integer) As Integer
get_width = lcar(i)
End Function
Function get_string_width(ByVal sir As String) As Integer
Dim i As Integer
Dim suma As Integer
For i = 1 To Len(sir)
suma = suma + get_width(Asc(Mid(sir, i, 1)))
Next
get_string_width = suma
End Function
Function get_nr_rows(ByVal sir As String, lung As Integer)
Dim temps As Variant
Dim lentemp As Integer
Dim i As Integer
Dim j As Integer
i = -1
j = 0
temps = Split(sir, vbCrLf)
For Each Item In temps
i = i + 1
j = j + CInt((get_string_width(temps(i)) / lung) + 0.5) - 1
Next


get_nr_rows = i + 1 + j
' returneaza numarul de linii + liniile suplimentare ..(deci cu 1 mai mic decat normal pentru fiecare linie)
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top