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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do You Show SuperScript in TextBox or Rich

Status
Not open for further replies.

NotSoVisual

Technical User
Aug 29, 2003
203
MX
I want to show powers in output to Text box AND also to print to paper. Have no clue.




 
You're looking for the SelCharOffset property.

rtb1.Text = "hello world"
rtb1.SelStart = 3 ' start after first L
rtb1.SelLength = 2 'Select LO
rtb1.SelCharOffset = 50 'Offset upwards by 50 twips


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

For tsunami relief donations

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
Thanks Johnvm, That works fine for Hello world" but I still have a problem.. Here it is what I am trying to do (withOUT the "^"

I have two arrays, one of Primes() and the other of their exponents as they appear in a prime factorization of a number.

For Counter = 1 to cnt

TxtANSWER = TxtANSWER + Str(Prime(Counter)) & "^" + _ Trim(Str(Ex(Counter))) + ", "

Next cnt

As the string builds I lose the previous formatting that I had. Let's say the loop started with 2 squared followed by 3 squared.. If I examined the output as the loop was progressing I saw the 2 squared when it was time to show the 3 squared it showed correctly after a 22 ! I need to be able to do your suggestion at two places at the same time.

In other words Hel ^(lo) +Wo ^(rld) If I make myself clear.

 
In each loop don't set the text value to the formatted text but the seltext property after setting the selstart property. So you are not changing what you already entered.

For Counter = 1 To cnt
TxtANSWER.SelStart = Len(TxtANSWER.Text)
TxtANSWER.seltext = Str(Prime(Counter)) & "^" + _Trim(Str(Ex(Counter))) + ", "
Next cnt



Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
Just set a new SelStart and SelLength each time. From your code I've constructed the string then substituted the ^ sign in a loop:

Code:
Dim intCurrent as Integer 'keeps track within the string
For intCounter = 1 To cnt
TxtAnswer = TxtAnswer & Str(Prime(intCounter)) & "^" & Trim(Str(Ex(intCounter))) & ",  "
Next intCounter
rtb1.Text = TxtAnswer
For intCounter = 1 To cnt
intCurrent = InStr(intCurrent + 1, TxtAnswer, "^")
rtb1.SelStart = intCurrent
rtb1.SelLength = 1
rtb1.SelCharOffset = 50
Next intCounter

Note that I've changed the Next statement to reflect the loop counter, and used the & as a string concatenator

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

For tsunami relief donations

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
I am not explaining my self well. I am trying to eliminate this character, "^", and use superscrip for the exponent.

5 3, 6 13

 
I am not explaining my self well. I am trying to eliminate this character, "^", and use superscrip for the exponent.

Example: I have two arrays,
Primes()=2,3,5,7,11
Exponents()= 10,5,2,1,1

desired out is:

210, 35,52, 71, 11 1

 
So try something like:

Dim i As Integer
For i = 0 To UBound(Primes)
RichTextBox1.SelStart = Len(RichTextBox1.Text)
RichTextBox1.SelText = Primes(i)
RichTextBox1.SelStart = Len(RichTextBox1.Text)
RichTextBox1.SelCharOffset = 50
RichTextBox1.SelText = Exponents(i)
RichTextBox1.SelCharOffset = 0
Next i



Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
Did you try the code I posted? It gives exactly the answer you've asked for!

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

For tsunami relief donations

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
Sorry clicked too soon - you obviously need to take out the ^ first!

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

For tsunami relief donations

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
Dr. Joe..thank you. works just like I want it to...now I have to figure out why. With this little diversion I am trying to program a prime factorization of a factorial as a personal challenge as I 'discovered' a way do it mentally atleast up to 60!)but I thought I'd try to program it. I did but the display is beyond me. I will study your code So I can learn

Johnwm. Your code works almost as well as Dr. Joes does. It uses the ^ in the display (which I wanted to eliminate and falls short on the double digit (which I could fix using len. I follow your code easier and between the both I will learn. Strings drive me nuts.

Thank you both.

Thank you both.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top