Adding a value into a string on a label vb.net [duplicate] - vb.net

This question already has answers here:
Replace characters in string with values
(3 answers)
Closed 3 years ago.
I'm trying to recall something from my brain from 6 years ago but I can't find it and the standard searches aren't bringing me joy.
I have a label like this:
Hello, this is my label and the value of the thing is: #value#. The label continues for a while here.
I need to update #value# in this instance with something from a database, however I can't remember how to without re-writing all the text again in the code. I know there's a way to do it, does anyone know this?
Thanks in advance!

If you are replacing existing text in the label, something like:
Dim myValueFromDatabase As String = "" ' Get the value from the database here
myLabel.Text = myLabel.Text.Replace("#value#", myValueFromDatabase)
Alternatively, you could use string interpolation:
Dim myValueFromDatabase As String = "" ' Get the value from the database here
myLabel.Text = $"Hello, this is my label and the value of the thing is: {myValueFromDatabase}. The label continues for a while here."

$"Hello, this is my label and the value of the thing is: {value}. The label continues for a while here."

Related

MS Access 2016 vba: Empty value passed from form field (text box)

I'm having a strange situation:
I have a simple form with 2 text boxes.
The second one has the vba code triggered after being updated.
For example: typing value to the first field, ENTER, typing value into the second field, ENTER and the code starts.
The code, initially, takes the values from the text boxes and assign them to the string variables (pre declared as strings), like:
test1 = Me.frmSSN.Value
The problem is, the test1 variable seems to be empty after the line above.
It seems to happen only when I type, for example this string:
073QB8KJ2D00A4X
It works fine, when entering CNB0K2W5JK
The tool is a simple serial number comparison.
Just for test, I've entered this line into the code:
aaa="073QB8KJ2D00A4X"
When running in the step-by-step mode and hovering mouse over the "aaa" I'm getting: aaa= and then nothing.
Not even single "" like aaa="" or so. Just aaa=
After retrying multiple things - I believe it's about the value I enter:
073QB8KJ2D00A4X
Could be, that for access/vba it's some control string or so?
I'm just dumb now...
Thanks in advance for any help
Marek
p.s. Source fields are plain text boxes. And here's the code:
Dim user As String
Dim 1stSN As String
Dim 2ndSN As String
1stSN = Me.frmSSN.Value
2ndSN = Me.frmHPSN.Value
Then the values are being used as a part of SQL query. The problem is - in this situation - query doesn't work, as the sql string looks like:
"Select * From sbo_SerialSource where SN like " and nothing after "like".
Debug shows the correct value (with serial number), but query fails with "syntax error" message. Seems like there are some strange "control characters" are being created/added.
That's it.
And I have to use the serial numbers as these "strange ones", because that's how they come from the vendor.

Visual Basic Trimming Letters From Integer

Is there a way to trim letters of a string? Or Convert a string to an integer removing its letters from it?
Story:
I have in which I have bunch of options on an application and all of them add up points depending on the option selected by the user. I gave them values like hsq2 hsq4 hsq6 and now I need to be able to get the one that is selected and remove letters from it and add up values. If you know a better way of doing this please let me know also..
The better way would be to use XAML and databinding to a rich ViewModel that has separate properties for each item's label and its score value as an integer. Then a method on your ViewModel would perform the sum of selected values and return it for data binding to the Total Score display. Search for MVVM if you want to know more about that approach.
However, since it looks like you're building a WinForms app, you could use the Tag property of each element to store the integer value. That's how I would have done it 7 years ago.
There are better designs you could use to avoid the issue, but to extract the number from a string, you could use a regex (now you have two problems, as they say!).
Dim match = RegEx.Match("blah2", "\d+")
If match.Success Then
Dim val = CInt(match.Value)
' val = 2
End If

Building object names from variables? [duplicate]

This question already has an answer here:
Cast to a control using the control name as a string [duplicate]
(1 answer)
Closed 8 years ago.
Sorry for this Newbie question, but it would help me a lot and I can't find a solution:
I want to use a string which I get from a database as object name like this:
NSString *objectName = string from Database
[self.objectName.titlelabel ....
In this case it would be setting a font for a button label.
How can this be achieved in Objective-C? The answers I found with NSMutableDictionary didn't help me.
NSString *objectName doesn't have a titleLabel property, however you could set the titleLabel of another UIButton as the string in objectName

Find object using string [duplicate]

This question already has answers here:
How To Get Control Property by "String Name"?
(6 answers)
Closed 9 years ago.
Is there some way in Visual Basic/Studio to find an object using a string?
I want to use it so that i can find objects by concatenating a variable with it.
Something along the lines of:
[Variable & "Main"].Visible = true
Just to elaborate, I don't want to use a table that iterates through all the objects in the form.
This is in VB.net. Any help?
Yes there is a way
Me.Controls(Variable & "Main").Visible = true
See Control.Controls property on MSDN
I don't have any official posting from a Microsoft website, but in my experience this is not possible. I would equate it to trying to use a string as a table name in SQL Server. One option is that you could iterate through the controls on the page (I'm guessing by the .Visible = true that you are dealing with controls) and look for a matching control ID. If found you will then have access to the properties for that control. Let me know if you would like to see an example. I'm not at a pc with Visual Studio so it would not be until tomorrow.

adding characters into a datagrid in vb.net

I'm new to vb.net. I would like to know how i could i/p a string via textbox and display its individual characters into a datagrid view in diff rows?
Are you only using a single column in the datagridview? if so you could do this easily by stepping through each character in the string and adding a row containing that character... see the code example below
InputString = TextBox1.Text
For a = 0 To InputString.Length - 1
Datagridview1.Rows.Add(InputString(a))
Next
Cant see why you'd want to do this though - If this isn't what you're trying to accomplish please give us more details