newbie here; Im trying to migrate my VB program to run in Tabs. so far I have been experimenting with creating Tabs at runtime with added controls. I figured out that I can create tabs and add controls at either FormLoad() or by an execute Button. However, I can not access those controls once the Tab is created. I can not get any info from a combo, text box either outside the created Tab. Here is a simple program that I manage to put together:
Public Class Form1
Inherits Form
Private tabControl1 As TabControl
Private tabPage1 As TabPage
Private tabPage2 As TabPage
Dim nm As String
Private Sub MyTabs()
Me.tabControl1 = New TabControl()
Me.tabPage1 = New TabPage()
Me.tabPage2 = New TabPage()
Dim txtBox1 As New Windows.Forms.TextBox With {.Parent = tabPage1}
Dim CalcButton As New Windows.Forms.Button With {.Parent = tabPage1}
CalcButton.Location = New Point(1572, 150)
CalcButton.Size = New Point(100, 50)
CalcButton.Text = "CALCULATE"
txtBox1.Location = New Point(1572, 258)
txtBox1.Size = New Point(70, 22)
txtBox1.Name = "Loc_num"
txtBox1.Text = "1"
nm = txtBox1.Text
Me.tabControl1.Controls.AddRange(New Control() {Me.tabPage1, Me.tabPage2})
Me.tabControl1.Padding = New Point(15, 10)
Me.tabControl1.Location = New Point(35, 25)
Me.tabControl1.Size = New Size(1800, 750)
' Selects tabPage1 using SelectedTab
Me.tabControl1.SelectedTab = tabPage1
Me.tabPage1.Text = "tabPage1"
Me.tabPage2.Text = "tabPage2"
Me.Size = New Size(2000, 900)
Me.Controls.AddRange(New Control() {Me.tabControl1})
AddHandler CalcButton.Click, AddressOf CalcButton_Click
End Sub
Private Sub CalcButton_Click()
Dim xx As Integer
Me.tabControl1.SelectedTab = tabPage1
xx = Convert.ToInt32(nm) ' IT KEEPS SHOWING A 1, EVENTHOU I CHANGED IT TO 4 WHEN FORM LOADS
MessageBox.Show(nm)
End Sub
Public Sub New()
MyTabs()
End Sub
Public Sub Main()
Application.Run(New Form1())
End Sub
End Class
Im not sure if its possible to continue of this path
Thanks for any help or comment
Related
I have a Mainform with textbox and button to search subform record
it works fine when i directly open Mainform and searching desire record
but when i open my form in Navigaition form it gives me error.
Download My Access Project What i have tried.
Below is my code:
Private Sub cmdSearch_Click()
Dim MainFK As Long
MainFK = DLookup("MainformID", "Subform", "SubformID =" & Me.txtSearch)
Debug.Print MainFK
DoCmd.SearchForRecord acDataForm, "Mainform", acFirst, "MainformID=" &MainFK
End Sub
See Screen Shot:
I think DoCmd.SearchForRecord is tricky on subforms. Try this instead:
Private Sub cmdSearch_Click()
Dim MainFK As Long
Dim rs As DAO.Recordset
Dim WhereStr As String
MainFK = DLookup("MainformID", "Subform", "SubformID =" & Me.txtSearch)
WhereStr = "MainformID=" & MainFK
With Me.Form
Set rs = .RecordsetClone
rs.FindFirst WhereStr
If _
rs.NoMatch _
Then
MsgBox "Subform record not match to mainform record"
Else
.Bookmark = rs.Bookmark
End If
End With
End Sub
Here's your file back: https://drive.google.com/file/d/0B-J5B7nFljZiLVJ1dEtoTVQwcXc/view?usp=sharing
I have more than 40 check-boxes in a single calc sheet, and I don't want to code each one of them. I just want a clear working code to get the name of checkbox.
In this program I have to manually type the name for the check-box within the macro code:
A="CheckBox1"
This is all I have so far:
Sub Marco1
Dim ocheckbox1
Dim oForm
Dim A
A="CheckBox1"
oForm = ThisComponent.Sheets(0).DrawPage.Forms.getByIndex(0)
ocheckbox1 = oForm.getByName(A)
if ocheckbox1.State = "0" then
if MsgBox ("Are you sure ?Note: It can't be re-edited", 292) = 6 then
ocheckbox1.Label = "Checked"
ocheckbox1.Enabled="False"
else
ocheckbox1.Label = "Not Checked"
End if
End if
End Sub
Assuming the macro is triggered by interaction with the checkbox:
Sub Macro1 (oEvent As Object)
Dim oCheckbox1 As Object
Dim sCheckbox1Name As String
oCheckbox1 = oEvent.source.model
sCheckbox1Name = oCheckbox1.Name
End Sub
I'm trying to use hyperlinks instead of buttons to run Basic macros. It seems to be more natural to me because hyperlinks are directly connected to a cell and buttons are not.
I'm using the following Formula:
=HYPERLINK("vnd.sun.star.script:Standard.Module1.Test?language=Basic&location=document";"Check")
It should call the Subroutine Test placed in the document's macros under Standard.Module1 and display the Text 'Check' in the Cell it is written.
This works absolutely fine with libreoffice 3.6.1.2 but it doesn't work at all with version 4.1.4.2. I can't see any errors it just happens nothing at all. I tried to simply click the Hyperlink and also to hold CTRL and click it. Same result - nothing.
When I use a button the macro works as expected.
Does anyone know how to solve this problem?
This seems to be a bug in Calc. The protocol vnd.sun.star.script runs in hyperlink URLs in Writer still in version 4.2. But in Calc it runs not.
As a workaround you could have the following function attached to the sheet event "Double click". Then the macro runs if you double click the cell with the =HYPERLINK formula.
The last two versions are the results of my first ideas. I will let them in the answer because of comprehensibility reasons. But this last version is the best workaround in my opinion. It will closest work like the original vnd.sun.star.script: URL.
public function Doubelclicked(target) as Boolean
if left(target.formula, 32) = "=HYPERLINK(""vnd.sun.star.script:" then
sFormulaHyperlink = target.formula
sMacroURLRaw = mid(sFormulaHyperlink, 13, instr(13, sFormulaHyperlink, ";") - 13)
target.formula = "=""" & sMacroURLRaw
sMacroURL = target.string
target.formula = sFormulaHyperlink
oDisp = createUnoService("com.sun.star.frame.DispatchHelper")
dim args(0) as new com.sun.star.beans.PropertyValue
args(0).Name = "URL"
args(0).Value = sMacroURL
oFrame = ThisComponent.CurrentController.Frame
oDisp.executeDispatch(oFrame, sMacroURL, "", 0, args)
end if
Doubelclicked = false
end function
Here are the previous versions:
public function Doubelclicked(target) as Boolean
if left(target.formula, 32) = "=HYPERLINK(""vnd.sun.star.script:" then
sMacroURL = mid(target.formula, 13, instr(13, target.formula, chr(34))-13)
oDisp = createUnoService("com.sun.star.frame.DispatchHelper")
oFrame = ThisComponent.CurrentController.Frame
oDisp.executeDispatch(oFrame, sMacroURL, "", 0, Array())
end if
Doubelclicked = false
end function
With this it is not possible to pass parameters in the macro URL. But if it only is the goal to get the address of the cell from which the macro was called, then this is possible because we have the target of the double click. So i have updated my workaround.
public function Doubelclicked(target) as Boolean
if left(target.formula, 32) = "=HYPERLINK(""vnd.sun.star.script:" then
lStartLocation = instr(13, target.formula,"&location=")
if lStartLocation > 0 then
lEndLocation = instr(lStartLocation + 1, target.formula,"&")
if lEndLocation = 0 then lEndLocation = instr(lStartLocation + 1, target.formula,"""")
sMacroURL = mid(target.formula, 13, lEndLocation - 13)
'msgbox sMacroURL
oDisp = createUnoService("com.sun.star.frame.DispatchHelper")
dim args(2) as new com.sun.star.beans.PropertyValue
args(0).Name = "TargetAddress"
args(0).Value = target.AbsoluteName
oFrame = ThisComponent.CurrentController.Frame
oDisp.executeDispatch(oFrame, sMacroURL, "", 0, args)
end if
end if
Doubelclicked = false
end function
Greetings
Axel
I have been able to change the list (or RowSource) of a Combobox dependant on whether an Optionbox has been selected using the following code:
Private Sub optYes_Click()
Options
End Sub
Private Sub optNo_Click()
Options
End Sub
Private Sub Options()
Select Case True
Case optYes.Value = True
cmb.Enabled = True
cmb.RowSource = "=Options!A1:A4"
Case optNo.Value = True
cmb.Enabled = False
End Select
End Sub
I would like to modify this slightly so that the Combobox list is limited to a group of Checkboxes that have been selected. So if I have 10 checkboxes denoting different options, and the user only selects 4 of them, then only those 4 will appear in the Combobox.
Here's how I would do it:
Private Sub Algeria_Change()
Options
End Sub
Private Sub Bangladesh_Change()
Options
End Sub
Private Sub Canada_Change()
Options
End Sub
Private Sub Denmark_Change()
Options
End Sub
Private Sub Options()
Dim names As Variant, name As Variant
Dim old As String
names = Array("Algeria", "Bangladesh", "Canada", "Denmark")
old = cmb
cmb.Clear
cmb.Enabled = False
For Each name In names
If Me.Controls(name) Then
cmb.AddItem Me.Controls(name).Caption
cmb.Enabled = True
If name = old Then cmb.SelText = old
End If
Next name
End Sub
If you need more checkboxes just add their name to names and call Options when they change.
I have a sub called addchartPrevious24()
This sub is being called on the initial load and when the user calls for a refresh. The job of this sub is to go out to an access database query the information. Populate into a dataset. Then create a chart and chart area. The dataset is then set as the datasource of the chart. My issue is if i reexecute the sub it does not update the chart with the new data although the dataset does get updated.
Public Sub addchartPrevious24()
Dim Connection As OleDb.OleDbConnection = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\manage.mdb;Jet OLEDB:Database Password=password")
Dim da1 As New OleDb.OleDbDataAdapter
Dim ds1 As New DataSet()
Dim Command As New OleDb.OleDbCommand
Connection.Open()
da1.SelectCommand = New OleDb.OleDbCommand("SELECT General_Counters_Table.product_id, Sum(General_Counters_Table.ulboardcyclecount) AS SumOfulboardcyclecount, ltrim(STR(Month(General_Counters_Table.Date_Time)))+ '/'+Ltrim(STR(Day(General_Counters_Table.Date_Time))) + '/'+ltrim(STR(Year(General_Counters_Table.Date_Time))) + ' hour ' +Ltrim(STR(Hour(General_Counters_Table.Date_Time))) as DATEConverted FROM General_Counters_Table where Date_Time >=(NOW()-1) and Date_Time <= (NOW()) GROUP BY General_Counters_Table.product_id, Year(General_Counters_Table.Date_Time), Month(General_Counters_Table.Date_Time), Day(General_Counters_Table.Date_Time), Hour(General_Counters_Table.Date_Time) ORDER BY Year(General_Counters_Table.Date_Time), Month(General_Counters_Table.Date_Time), Day(General_Counters_Table.Date_Time), Hour(General_Counters_Table.Date_Time)", Connection)
da1.Fill(ds1, "Throughput")
Connection.Close()
'Defines Chart and Chart Area
Dim chart1 = New Chart()
Dim chartarea1 As ChartArea = New ChartArea()
TabPage2.Controls.Add(chart1)
chartarea1.Name = "ChartArea1"
chart1.ChartAreas.Add(chartarea1)
Chart1.Location = New System.Drawing.Point(10, 10)
chart1.Name = "Chart1"
Chart1.Size = New System.Drawing.Size(800, 400)
chart1.TabIndex = 0
chart1.Text = "Chart1"
chartarea1.AxisX.LabelStyle.Angle = -60
chartarea1.AxisX.Interval = 1
chartarea1.AxisY.MajorGrid.Interval = 5
chartarea1.BackColor = Color.Azure
chartarea1.ShadowColor = Color.Red
chartarea1.Area3DStyle.Enable3D = True
chartarea1.AxisX.MajorGrid.Enabled = False
chartarea1.AxisX.LabelStyle.Font = New System.Drawing.Font("Times New Roman", 11.0F, System.Drawing.FontStyle.Italic)
'Legend
Dim legend1 As Legend = New Legend()
legend1.Name = "Legend1"
chart1.Legends.Add(legend1)
'Series
Dim series1 As Series = New Series()
series1.ChartType = SeriesChartType.StackedColumn
series1.ChartArea = "ChartArea1"
series1.Legend = "Legend1"
series1.Name = "Throughput"
chart1.Series.Add(series1)
chart1.Series("Throughput").XValueMember = "DateConverted"
chart1.Series("Throughput").YValueMembers = "sumofulboardcyclecount"
chart1.Series("Throughput").IsValueShownAsLabel = True 'shows label on datapoint
chart1.DataSource = ds1.Tables("Throughput")
chart1.Update()
chart1.DataBind()
End Sub
I had the same problem, a resolution is presented for "This Question"
Try clearing your data points using:
Chart.Series.Points.Clear()
and then adding them again.