I am quite new to VB coding but I do understand some of the basics. I want to create a loop that checks the value within 8 text boxes and enabled a tick box next to the respected text box if it not blank. I am not quite sure on the syntax. I have 8 text boxes called Textbox1 : Textbox8 and 8 checkboxes with names checkbox1-8. This is the code I have already but I just need a bit of help with the syntax.
For i = 1 To 8
If Textbox(i) = "" Then
checkbox(i).enabled = false
else
checkbox(i).enabled = true
End If
Next
Something like:
For i = 1 To 8
Me.Controls("checkbox" & i).Enabled = (Nz(Me.Controls("Textbox" & i).Value) <> "")
Next
Related
I have been trying to use a textbox in VB6 to acquire 6 different random numbers chosen by the user to use in part of my program. I have tried many different approaches in different areas of the code. Best I have gotten so far is in the keypress section. I set up an array to store the 6 entries buy fail to be able to get past storing one number in the first element. I'm using a for next loop to cycle through the elements but the textbox.setfocus will not work properly in the loop. I clear the box then setfocus after I assign the number to an element in the array. The only other way I'm thinking this would work is to hide the single box and show 6 hidden ones and then they can tab or I can hide each one again as they fill up.
Here's a snip of that code so one should get an idea what I'm trying to do here.
Private Sub Inbox_Keypress(KeyAscii As Integer)
Select Case KeyAscii ' Determine keypress
Case vbKey0 To vbKey9 'Only the numbers
Case vbKeyBack, vbKeyClear, vbKeyDelete ' Accept these keys
Case vbKeyLeft, vbKeyRight ' Arrow keys
Case 13 ' Enter
If GenOpt(5).Value = True Then
For c = 1 To 6
Gen6_user(c) = Inbox.Text
'Select Case KeyAscii
' Case 13
Talkbox.Caption = "Please enter the next user number for Generator 6"
'Case Else
' MsgBox Msg, style, title
'End Select
If c = 6 Then Exit For
Do
Inbox.Text = ""
Inbox.SetFocus
Loop Until KeyAscii = 13
Next
For c = 1 To 6
Msg6.Print Gen6_user(c)
Next
Else
User_number = Inbox.Text ' Assign any final value to User_number variabl)
Generate.SetFocus
'Generate_Click ' Call generate function
End If
Any help would be appreciated
Journey
I am at work and I don't have VB6 handy here... but, this should work (maybe with a few little tweaks, I am sure you can figure those out):
Dim x As Integer = 1
Dim myArray(6) As Integer
Private Sub TextBox1_KeyUp(KeyCode As Integer)
If KeyCode = 13 Then
myArray(x) = TextBox1.Text
x = x + 1
TextBox1.Text = ""
End If
If x = 6 Then
Debug.Print("Here you check your numbers?")
End If
End Sub
New to vba programming and was hoping to get some help on a little program I'm having difficulty with. What I would like for this code to do is extract specific data from an element. So in this example I would like to extract the phone number for each person.
I can get the code to print all of the data in the element, but I only want to extract specified information not everything in the element. Any help would be awesome.
Set Elements = IE.Document.getElementById("member-items").getElementsByTagName("p")
'Get information
r = 0
c = 0
For Each Element In Elements
If Element.innerText Like "phone" Then
Sheet1.Range("A1").Offset(r, c).Value = Element.innerText
Debug.Print Element.innerText
r = r + 1
End If
Next Element
Okay I figured it out. I did not realize the text is CAP sensitive. So instead of using "phone" I used "Phone" with a CAP "P" and the code worked perfectly. Rockie mistake. =). Hope this helps any other newbies out there. And I used the following code instead:
For Each Element In Elements
If InStr(Element.innerText, "Phone") Then
Sheet1.Range("a1").Offset(r, c).Value = Element.innerText
Debug.Print Element.innerText
r = r + 1
End If
Next Element
You might already know the problem by the title.
I'm making a game, where i want the level number to change to 1 (from the first level 0). My code to change from level 0 to 1 is:
'Level 0 (Tutorial)
If levelNum.Text.Contains("0") Then
levelNum.Text = "1"
ButtonNext.Enabled = False
ButtonLeave.Enabled = True
ButtonBreak.Enabled = True
ButtonCoffee.Enabled = True
ButtonCoffeeForBoss.Enabled = True
End If
But it sets the label text to 2 instead of 1, wich was written (Line 3 of code above).
EXAMPLE:
http://cdn.makeagif.com/media/11-24-2013/9p4CcG.gif
Does anybody know how to fix that?
Maybe make a variable with "1" in it and then use that?
*TESTING THAT*
No, didn't work...
Could it be because it's starting on level 0?
I have no idea.
I'm using VB Express 2013.
I need a help in VBScript or either in QTP for the below case.
For example:
I have nearly 40 items in the weblist. I have only one item in the Excel sheet that is one among the 40 in the weblist. If I run the script, the one in the Excel should be select in the weblist. How do I perform this? I tried many scenarios, but couldn't get it to work.
Below are some of the sample pieces of code I tried in QTP:
ocount=Browser("name:=brw").Page("title:=brw").WebList("htmlid:=tabContainerBrandSite_123&rtyoh").GetROProperty("items count")
msgbox ocount
var7=mySheet2.Cells(2,"C")
For k=2 to ocount
ocount2=Browser("name:=brw").Page("title:=brw").WebList("html id:=tabContainerBrandSite_123&rtyoh").GetItem(k)
msgbox ocount2
merchantName = DataTable("Merchant_Name","Global") 'an example if value is saved in global sheet
items_count = Browser("Sarit").Page("Sarit_2").WebList("txtVendorCode").GetROProperty("Items Count") 'This will get all the items from your weblist.
i = 1
Do
webListName = Browser("Sarit").Page("Sarit_2").WebList("txtVendorCode").GetItem(i)
'this will get first value from the web list
If merchantName = webListName Then 'comparing first value from your value from global sheet
Browser("Sarit").Page("Sarit_2").WebList("txtVendorCode").Select(i) 'selects that value
Exit do 'because it has found your only value from the local sheet, it exits
else
i = i + 1
End If
Loop While i <= items_count
[The description is a bit fudged to obfuscate my real work for confidentiality reasons]
I'm working on a QTP test for a web page where there are multiple HTML tables of items. Items that are available have a clickable item#, while those that aren't active have an item# as plain text.
So if I have a set of ChildObjects like this:
//This is the set of table rows that contain item numbers, active or not.
objItemRows = Browser("browserX").Page("pageY").ChildObjects("class:=ItemRow")
What is the simplest way in QTP land to select only the clickable link-ized item #s?
UPDATE: The point here isn't to select the rows themselves, it's to select only the rows that have items in them (as opposed to header/footer rows in each table). If I understand this correctly, I could then use objItemRows.Count to count how many items (available and unavailable) there are. Could I then use something like
desItemLink = Description.Create
desItemLink("micclass").value = "Link"
objItemLinks = objItemRows.ChildObjects(desItemLink)
To get the links within only the item rows?
Hope that clarifies things, and thanks for the help.
I think I have this figured out.
Set desItemLink = description.create
desItemLink("micclass").value = "Link"
desItemLink("text").RegularExpression = True
//True, Regex isn't really required in this example, but I just wanted to show it could be used this way
//This next part depends on the format of the item numbers, in my case, it's [0-9]0000[0-9]00[0-9]
For x = 0 to 9
For y = 0 to 9
For z = 0 to 9
strItemLink = x & "0000" & y & "00" & z
desItemLink("text").value = strItemLink
Set objItemLink = Browser("browser").Page("page").Link(desItemLink)
If objItemLink.Exist(0) Then
//Do stuff
End If
Next
Next
Next
Thanks for your help anyways, but the code above will iterate through links with names in a given incrementing format.