Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Reference textbox value in Rich Textbox


Reply
 
Thread Tools Display Modes
  #1  
Old 04-25-2012, 06:04 AM
Matanic Matanic is offline
Newcomer
 
Join Date: Mar 2012
Location: Florida
Posts: 23
Default Reference textbox value in Rich Textbox


In my app I produce a overview of a process stating that things are Okay or there are warnings. Currently I find if the value is under, within or over a percentage range which works fine.

What I would love to do is reference the actual value of say textbox.19.text in the RichTextBoxes. Like this

RichTextBox2.text="...." val(textbox19.text) "..."

The current code:

'Injection Pressure overview / warning

If Val(TextBox19.Text) > Val(TextBox6.Text) Then RichTextBox2.Text = "The converted molding process requires injection pressure greater that what this machine is capable of and should not be used without thourgh Engineering and Quality review."

Ideas?

Thanks All,
Reply With Quote
  #2  
Old 04-25-2012, 06:24 AM
DrPunk's Avatar
DrPunk DrPunk is offline
Senior Contributor

* Expert *
 
Join Date: Apr 2003
Location: Never where I want to be
Posts: 1,405
Default

The text in a textbox is a String like any other String.

You append strings to other strings using the ampersand (i.e. &).

Code:
"Some Text " & aStringVariable & " some more text " & aTextBox.Text & " final bit of text " & str(anIntegerVariable)
Note that the Val() function converts the parameter passed to a numeric data type which is a waste of time when appending a string to a string (in this instance it would convert the String to a Double and then automatically convert that Double back to a String to append it to the String. Those two conversions are a waste).
__________________
There are no computers in heaven!

Last edited by DrPunk; 04-25-2012 at 06:29 AM.
Reply With Quote
  #3  
Old 04-25-2012, 08:17 AM
Matanic Matanic is offline
Newcomer
 
Join Date: Mar 2012
Location: Florida
Posts: 23
Default

Perfect.

Point taken on using Val, removed all those and everything hums right along.

Sure am glad this is just proof of concept and not a career path for me!!!
Reply With Quote
  #4  
Old 04-25-2012, 08:25 AM
DrPunk's Avatar
DrPunk DrPunk is offline
Senior Contributor

* Expert *
 
Join Date: Apr 2003
Location: Never where I want to be
Posts: 1,405
Default

You shouldn't remove them all.

I was only really refering to the...
Code:
RichTextBox2.text="...." val(textbox19.text) "..."
... one in your post.

The other Val()s you posted ("If Val(TextBox19.Text) > Val(TextBox6.Text) ...") are necessary because you're comparing the numerical values of the Text so you want to convert the Strings (i.e. the .Text) into numbers to compare.

Sorry if I confused things. Hopefully I've not made it worse.
__________________
There are no computers in heaven!
Reply With Quote
  #5  
Old 04-25-2012, 09:45 AM
Matanic Matanic is offline
Newcomer
 
Join Date: Mar 2012
Location: Florida
Posts: 23
Default

Lol I just figured out why I had to do that, if there is missing input on the form and the user trys to 'convert the molding process' then I got casting errors. Took awhile to hammer through that.

Ideally what would be sweet is if the button click that runs the math on the sheet "LOOKS" for all the inputs are there and are numbers and then allows the sheet to run. If all the inputs are not met or are not numbers it would give a msgbox warning and stop execution until all is good and the button is clicked again. Iwas able to get a msgbox event to pop up with the warning but still executed the rest of the code My wife is QA for IVR systems and she thinks I lazy because I work around lots of stuff lol. I tell her I am not a coder I am an Industrial Engineer!!

But I think I am going to spend more time on trying to catch those exceptions, clean this up a little more. What I have I am very very happy with it works and looks wonderful. Just needs the finer points like using the actual textbox.text values rather than just saying "your between this and this"

This is a great forum I find 99% of my answers searching and reading old posts here
Reply With Quote
  #6  
Old 04-25-2012, 10:03 AM
DrPunk's Avatar
DrPunk DrPunk is offline
Senior Contributor

* Expert *
 
Join Date: Apr 2003
Location: Never where I want to be
Posts: 1,405
Default

It's worth checking the values yourself instead of relying on exceptions. You can generally give the user more information if you check the values yourself. If you check yourself then you can go as far as directing the user towards which parameter is not valid if you really want.

But what you're talking about would break down to...
Code:
If ValidFields Then
    Do The Math
Else
    Msgbox a warning
End if
So it's then how you go about validating the fields. If you're just interested in a String being a number then you can use the IsNumeric function. I'm assuming that would return False for an empty String although I can't confirm that.

So you could probably get away with...
Code:
If IsNumeric(textbox6.text) and IsNumeric(textbox19.text) Then
   DoTheMath
Else
   msgbox a warning
End if
Depending on how many textboxes you've got then the If could get pretty messy. But from the comments you've made it sounds like you wouldn't be that bothered about that anyway
__________________
There are no computers in heaven!
Reply With Quote
  #7  
Old 04-25-2012, 07:48 PM
Matanic Matanic is offline
Newcomer
 
Join Date: Mar 2012
Location: Florida
Posts: 23
Default

Your right on both counts Dr. It is messy and I don't care because it works

Proof of concept is ALL this needs to be

Thanks again
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->