Sorry. i am officially new in Visual Basic.
I have created a TextBox in my form. In "View Code" i want to access the Text attribute
(I mean TextBox.Text)
,but the object only gives me these 4: Count,Item,LBound,UBound
Maybe you're changing the Index property instead of the TabIndex property so that it would become a control array thus UBound, LBound, Count and Item properties are present.
And i suspect you are using Visual Basic 6 instead of VB.Net.
See link here the VB6 has Index property that is for Control Array.
My guess, without seeing your code is that your syntax is somehow interacting with an array, try this code:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.TextBox1.Text = "Hello World"
End Sub
End Class
Note: The above code represents the default names for a Form, a new TextBox dragged and dropped onto the designer inside of the form's Load event handler.
Are you possibly copying and pasting a textbox rather than double clicking the object in the toolbox. If you look in the name of the object in the properties window you would see txtName(0)
Related
So I mostly use Microsoft Excel for a lot of my work and the most "Programming" I do is writing basic logical functions in excel.
I am setting up a windows form in Visual Studio 2013 and I want to the end user to be able to be able to confirm that the data they input into TEXTBOX1 matches what is in TEXTBOX2.
So normally in excel I can just write =IF(C2=D2,"Yes","No")
So basically I want to be able to input data in the carton field and then in the label field and if it matches I want it to say yes in the text box at the bottom.
I tried writing
If CartonBarcode = LabelBarcode Then
PartCheck = "Yes"
Else : PartCheck = "No"
End If
but that hasn't worked - I am very new to VB so please be gentle.
Eventually I also want to be able to append the scanned data (If the two text boxes match) into an excel spreadsheet.
Thanks in advance for all your help =)
Thanks for your help Mark - that makes a lot of sense.
I added this IF Statement to the PartCheck text box but it doesn't seem to display Yes or No regardless of what I put in.
It now throws two errors (look to be the same error on each line.)
Value of type 'String' cannot be converted to 'System.Windows.Forms.TextBox'
Any further help you can provide would be fantastic
Screenshot of errors
I then changed PartCheck = "Yes" to PartCheck.Text = "Yes" and it runs but then nothing displays in the PartCheck Text Box
In WinForms, TextBox and other GUI components (e.g. Label, Button) are objects, with properties and methods to interact with them. If you want to compare the text that has been entered into two TextBox objects, you will need to compare their Text properties. e.g.
Update
Updated code below based on your updated question. You are correct that you need PartCheck.Text = "Yes" to set it correctly. Your current issue is when you are performing the check. You are handling the TextChanged event for your PartCheck TextBox, but your logic should really be triggered when either the CartonBarcode or LabelBarcode text is changed. You can either have TextChanged handlers for both of those TextBox controls, and call a common subroutine to perform the check, or have a common TextChanged handler, as shown below:
Private Sub Barcode_TextChanged(sender As Object, e As EventArgs) _
Handles CartonBarcode.TextChanged, LabelBarcode.TextChanged
If CartonBarcode.Text = LabelBarcode.Text Then
PartCheck.Text = "Yes"
Else
PartCheck.Text = "No"
End If
End Sub
In a VB6 project, I would like to be notified when an edit control (text field) has been updated (i.e. : character string has been added by a user into the text field).
I did not find any documentation on the different events which can be catched for an edit MFC control.
Thanks in advance.
Its the _Change event. However, I personally do not like this event since it is notoriously unreliable.
Private Sub txtYourTextFieldControl_Change()
' some code here
End Sub
* edit *
We are talking about VB6 textbox, correct? I am not sure what MFC has to do with this.
I have the following problem. I wrote simple macro which shows MsgBox before print dialog. Here is source:
Public WithEvents App As Application
Private Sub App_DocumentBeforePrint(ByVal Doc As Document, Cancel As Boolean)
MsgBox "aaaaa"
End Sub
Private Sub Document_New()
Set App = Application
End Sub
When I open one document from template with this macro, everything is OK. But I have a problem when I open two documents from this template at same time. When I click to print button, MsgBox shown up twice. Any ideas?
Edit:
When I create document from this template and create another new document, which isnt't based on this template (both of this documents are opened at the same time) and I print from that new empty document, MsgBox shown up. This is also wrong right?
You have created application-level events that fire every time any document is being printed. They are triggered once for every document that has this code in it, so every time you print a document you will get the msgbox once for every open document that has the code in it, whether or not the document that's printing has the code in it.
So, the behaviors aren't wrong, although clearly they are not what you want.
You should put the Before_Print event in the ThisDocument module of your template. That way the event will only happen once, and only when the document being printed has the code in it.
You could put a check in your App_DocumentBeforePrint sub to check whether the instance of the application object which is firing the event is the instance that contains the active document:
If Me <> ActiveDocument Then Exit Sub
I'm using MVVM architecture in a WP7 phone app. My current view is a user control, which exists inside of a parent page (standard page -- not stand-alone user control). I have passed the main page as a parent to a "parent" property of the user control, and I can access pretty much any control in the parent. For example: this works to access a lockable pivot in the parent:
Dim p As LockablePivot
p = MyParent.FindControl("myLockablePivot")
If p IsNot Nothing Then
..do something with the pivot
End If
My problem is in accessing the ApplicationBar in the parent. This does not work. I have triple checked the x:Name assigned to the application bar. (null reference exception):
Dim ap As ApplicationBar
ap = MyParent.FindName("appBar")
ap.IsVisible = False
Any help would be appreciated.
I hit the same issue, but as Nigel points out in this answer, the
"ApplicationBar isn't a standard Silverlight object, because of that it doesn't really fit in the visual tree, can't be bound to and x:Name doesn't work."
It turns out that there is an ApplicationBar property on the PhoneApplicationPage class. You can use it to access the Application Bar and then grab the Buttons or MenuItems from there.
Here is a C# example of what I did in my page constructor to localize the text:
public MyPage()
{
InitializeComponent();
(this.ApplicationBar.Buttons[0] as ApplicationBarIconButton).Text = AppResources.event_add_menu_item;
}
Admittedly, using the index to locate the item and then having to cast is unfortunate, but at least it works!
I have a dialog in vb6 which changes the values being displayed in its parent dialog.
The x1 is displayed in txt_c1 text in parent dialog and it has a txt_1validate function too for the text box. Now i want to change the value of txt_c1 txtbox from child dialog and then call its validate function. But the problem is that txt_c1 is not available in child dialog.
Please note that i am working in vb6 in the MS VB 6.0 IDE
Forms are just classes and can therefore be instantiated explictly (and you will probably find your life easier if you do rather than using the automatic instantiation in VB6) and references to forms can be assigned.
You can solve your problem by creating a public property on your child dialog (Form1.frm) of type Form that you set to the instance of the parent dialog thus giving you access to the controls andd methods on the parent from the child.
My VB6 is somewhat rusty (and I don't have an installed instance available) so this isn't going to be actual, correct code - but something along the lines of the following should work
In the code that calls the child:
Form childDialog = new Form1
childDialog.Parent = this
childDialog.ShowModal
Then in the child dialog:
Parent.txt_c1 = newValue
if not Parent.Validate then
...
end if