Checkbox in VB6.0 with multiple forms - vb6

I'm still beginner in programming pls understand me..I have two forms namely "form1" and "form2"...I have this code in my "form1"
Private Sub chkRegisteredLocation_Click()
If checkbox1.value = 1 Then
datacombo1.Enabled = True
Else
checkbox1.Enabled = False
datacombo1.Text = ""
End If
End Sub
Now in my "form2" how do I know if my checkbox1 is True or Checked?

Already solved...
public blnCheckbox as Boolean
Private Sub chkRegisteredLocation_Click()
If checkbox1.value = 1 Then
blnCheckbox = True
datacombo1.Enabled = True
Else
checkbox1.Enabled = False
datacombo1.Text = ""
End If
End Sub
Form2
If form1.blnCheckbox = True Then
msgbox("Checked")
end If

Related

How do you work a tryCatch with numbers and Letters

I am supposed to ADD a TRY-CATCH to make sure the user inputs a numeric value and not a letter value. It works fine when you enter a letter and reads "there was an error, please enter digits" but then the program stops and says there was an error :
Here is my code
Dim intPoints As Integer
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
txtPoints.Clear()
End Sub
Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
End
End Sub
Private Sub btnReward_Click(sender As Object, e As EventArgs) Handles btnReward.Click
Try
intPoints = txtPoints.Text
intPoints = Convert.ToInt32(txtPoints.Text)
Catch ex As Exception
Finally
MessageBox.Show("There was an error, please enter digits")
End Try
'intPoints = Convert.ToInt32(txtPoints.Text)
If txtPoints.Text <= 0 Then
MessageBox.Show("You cannot have less than 0")
End If
If txtPoints.Text = 1 Then
MessageBox.Show("Keep Trying")
End If
If txtPoints.Text = 2 Then
MessageBox.Show("Keep Trying")
End If
If txtPoints.Text = 3 Then
MessageBox.Show("Keep Trying")
End If
If txtPoints.Text = 4 Then
MessageBox.Show("Keep Trying")
End If
If txtPoints.Text = 5 Then
MessageBox.Show("You're Gettomg close, just a few more!")
End If
If txtPoints.Text = 6 Then
MessageBox.Show("You're Gettomg close, just a few more!")
End If
If txtPoints.Text = 7 Then
MessageBox.Show("You're Gettomg close, just a few more!")
End If
If txtPoints.Text = 8 Then
MessageBox.Show("You're Gettomg close, just a few more!")
End If
If txtPoints.Text = 9 Then
MessageBox.Show("Almost, just one more!")
End If
If txtPoints.Text = 10 Then
MessageBox.Show("Awesome! You earned a reward!")
End If
If txtPoints.Text >= 11 Then
MessageBox.Show("You cannot have more than 10 points")
End If
End Sub
' A computer uses
End Class

Signal timed ruby gtk image change without button_press_event, how to trigger looping

The line: pics.box.signal_connect("button_press_event"){pics.nuImage}, triggers nuImage and adds 1 to the picindex counter upon clicking, making the current image destroy, and next image show. I would like to make this automatic, like a slideshow without having to click. It needs to show a new image every x amount of seconds, using a sleep or something like GLib.timeout_add_seconds (), but I do not understand how to implement these options to continue looping without any user input. Thank you for your help, I am very new to ruby.
require 'gtk2'
class Pics
attr_accessor :pile, :picindex, :imgLoaded, :image, :box, :window, :time
def initialize
#window = Gtk::Window.new()
#window.signal_connect("destroy"){Gtk.main_quit}
pic1 = "1.jpg"
pic2 = "2.jpg"
pic3 = "3.jpg"
pic4 = "4.jpg"
#pile = [pic1, pic2, pic3, pic4]
#picindex = 0
self.getImage
#box = Gtk::EventBox.new.add(#image)
#time = true
end
def nuImage
#box.remove(#image)
#picindex = #picindex + 1
#picindex = 0 if #picindex == #pile.length
self.getImage
#box.add(#image)
#box.show
end
def getImage
#imgLoaded = #pile[#picindex]
img = Gdk::Pixbuf.new(#imgLoaded, 556, 900)
#image = Gtk::Image.new(img)
#image.show
end
end # class Pics
pics = Pics.new
pics.box.signal_connect("button_press_event"){pics.nuImage}
pics.window.set_default_size(556, 900)
pics.window.add(pics.box)
pics.window.show_all
Gtk.main
the following code is an implementation:
GLib::Timeout.add(1000) do
pics.nuImage if pics.time
true
end
pics.window.signal_connect("key_press_event") do |_window, event|
case event.keyval
when Gdk::Keyval::GDK_KEY_space
pics.time = !pics.time
end
end
more details: http://ruby-gnome2.sourceforge.jp/hiki.cgi?GLib%3A%3ATimeout
related: Ruby GTK Pixbuf timed image change

Ruby script to check if a worksheet is present in workbook

I need to know whether a sheet exists in the workbook or not using ruby.
code
excel = WIN32OLE.new('Excel.Application')
excel.visible = false
workbook = excel.Workbooks.Add();
worksheet = workbook.Worksheets.Add()
workbook.Worksheets("header_new").copy(workbook.Worksheets("header_old"))
I need to copy the content of header_old into header_new only if the later sheet exists else throw an error message.
Here is a good blog-post for Automating Excel using Ruby :
# Require the WIN32OLE library
require 'win32ole'
# Create an instance of the Excel application object
xl = WIN32OLE.new('Excel.Application')
# Make Excel visible
xl.visible = 1
# Add a new Workbook object
wb = xl.workbooks.add
# Get the first,second Worksheet
ws1,ws2 = wb.worksheets(1),wb.worksheets(2)
# Let rename those sheet
[ws1,ws2].each.with_index(1) { |s,i| s.name = "test_sheet_#{i}" }
# Lets check how many worksheet is present currently
totale_sheet_count = wb.sheets.count
# now let's check if any sheet is having the name, as you are looking for
1.upto(totale_sheet_count).any? { |number| wb.worksheets(number).name == "foo" } # => false
1.upto(totale_sheet_count).any? { |number| wb.worksheets(number).name == "test_sheet_2" } # => true
To understand this you first need to look into the method #any?, #upto and #raise.
Here is a final code to meet your needs :
require 'win32ole'
excel = WIN32OLE.new( 'Excel.Application' )
excel.visible = true
wb = excel.workbooks.open( "path/to/your_excel.xlsx" )
totale_sheet_count = wb.sheets.count
# below line checking if your excel has any worksheet named as "header_new". If it
# find such a named sheet, Enumerable#any method will return true, otherwise false.
bol = 1.upto(totale_sheet_count).any? { |number| wb.worksheets(number).name == "header_new" }
begin
raise( RuntimeError, "Required sheet is not present" ) unless bol
workbook.worksheets("header_new").copy(workbook.worksheets("header_old"))
rescue RuntimeError => ex
puts ex.message
end

VBS If Then Else

I'm new to VBS and I'm attempting to make a start on a UAC in Windows - A will to do and in turn, learn.
I don't understand why I keep getting a syntax error on the line before the last End If
If you could help, I'd be greatly appreciative!
CurPass = ReadIni("C:\Program Files\User Account Control\ident.ini", "pass", "pass")
InpPass = inputbox("Please enter your current password:")
If InpPass = CurPass Then
NewPass = inputbox("Please enter your new password")
if NewPass=CurPass Then
KpPass=msgbox("Your new password is the same as your old password. Keep old password?",4+32,"UAC")
if KpPass=7 Then MsgBox("Please try again")
end if
Else
RNewPass = inputbox("Please re-enter your new password")
end if
if RNewPass=NewPass then
WriteIni "C:\Program Files\User Account Control\ident.ini", "pass", "Pass", NewPass
else msgbox("Your new passwords do not match. Try again.")
end If
else msgbox("Incorrect password")
End if
There is no If .. Then for your last Else .. End If. This would be obvious immediately, if you had used proper indentation.
Update: Above diagnosis is wrong.
I think you want this structure:
CurPass = ""
InpPass = ""
If InpPass = CurPass Then
NewPass = ""
If NewPass = CurPass Then
KpPass = ""
If KpPass = "7" Then
KpPass = "4711"
End If
Else
RNewPass = ""
End If
If RNewPass = NewPass Then
RNewPass = "xx"
Else
RNewPass = "yy"
End If
Else
CurPass = "whatamess"
End If
Then VBScript lost its way when you wrote:
if KpPass=7 Then MsgBox("Please try again")
end if
You can have 'short ifs' like
If Condition Then OneStatementAction
but then there should be no End If. It's a bit like omitting {} for single line/statement conditionals in other C alike languages. That is: better avoided.
End IF is a expresion that tells to VB.NET that you done your Conditions.
Every IF may close with an END IF
so your code may be like:
If textbox1.text = "Cat" Then
Do something
Else
Do not do that thing
End If
Check your code again and avoid writing End IFs and then elses look:
If textbox1.text = "Cat" Then
Do something
End IF
Else
Do not do that thing
End If
// This will not work! You can t have more than one IF in a contition:
This is incorect:
IF something Then
IF blabla bla then
Else
Endif
See here a link where you can learn how to use therse:
http://msdn.microsoft.com/en-us/library/752y8abs.aspx

How to make a control invisible?

I've made several TextCtrls and Button, but currently users of my application don't want to see them. So I have to hide them temporary (for current build).
Here they are:
class MainFrame < Wx::Frame
def initialize (parent = nil)
super nil,:title=>"sometitle",:size=>[600,600]
set_sizer Wx::BoxSizer.new Wx::VERTICAL
#tag1 = Wx::TextCtrl.new self
sizer.add_item #tag1,:flag=>Wx::RIGHT|Wx::EXPAND
#tag1.set_value 'property'
#tag1title = Wx::TextCtrl.new self
sizer.add_item #tag1title,:flag=>Wx::RIGHT|Wx::EXPAND
#tag1title.set_value 'title'
#tag2 = Wx::TextCtrl.new self
sizer.add_item #tag2,:flag=>Wx::RIGHT|Wx::EXPAND
#tag2.set_value 'description'
#tag2title = Wx::TextCtrl.new self
sizer.add_item #tag2title,:flag=>Wx::RIGHT|Wx::EXPAND
#tag2title.set_value ''
#button_parse = Wx::Button.new self
sizer.add_item #button_parse
#button_parse.label = "Parse XML"
evt_button #button_parse, :click_parse
# ......
end
# ......
end
I see nothing about it in docs and Google is also not a friend for me today.
Since they are in a sizer, then you'll be able to use Sizer#show.
Boolean show(Sizer sizer,
Boolean show = false,
Boolean recursive = false)
This works for BoxSizer and FlexGridSizer.

Resources