Using Range with Cells() - range

I am trying to set a range in a worksheet named myws:
I use Set myws = Sheets(i)
Then I try to set the desired range.
Why does this work:
Set myrange = myws.Range("A1:CH15000")
But this doesn't:
Set myrange = myws.Range(Cells(1, 1), Cells(15000, 85))
Ultimately I would like to replace the 15000 and 85 with variables.
I have tried several variations on the theme without success.

Related

Libreoffice calc - how to write a same value into a range

I know how to 'select' a range in LO (7.2.4.1) Calc BASIC ....
ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("D1:H6")
But how to write a value, e.g. "1", into that range using BASIC?
myRange = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("D1:H6")
myRange.Value = 1
Gives an "property or method not found" error. But I can't find any properties or values to go after Range to allow me to do what I want. Flailing around and trying
myRange.setValue = 1
myRange.writeValue = 1
myRange.setString = "1"
and numerous other variants don't work either.
Would really appreciate the solution. Thanks.
You can edit the value of an individual cell, but not the entire range. You will have to iterate over all the cells in the range one at a time, changing the value of each of them.
Sub Set1ToD1H6
myRange = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("D1:H6")
For i = 0 To myRange.getRows().getCount()-1
For j = 0 To myRange.getColumns().getCount()-1
myRange.getCellByPosition(j, i).setValue(1)
Next j
Next i
End Sub
But since the read-write operation to a cell is comparable in time to the read-write operation to a whole range, it is preferable to use another method - to prepare data in an array and write from it to a range in one operation:
Sub Set1ToRange
myRange = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("D1:H6")
dataOfRange = myRange.getData()
For i = LBound(dataOfRange) To UBound(dataOfRange)
For j = LBound(dataOfRange(i)) To UBound(dataOfRange(i))
dataOfRange(i)(j) = 1
Next j
Next i
myRange.setData(dataOfRange)
End Sub
(For your example, this will be approximately 30 times faster, for a larger range the time winnings will be even more significant)
The .getData() and .setData() methods work on numeric range values. To work with text strings (and numbers), use .getDataArray() and .setDataArray(), for working with cell formulas use .getFormulaArray() and .setFormulaArray()

Region cannot be empty error with Terrain:FillRegion()?

I try this:
workspace.Terrain:FillRegion(Region3.new(Vector3.new(2048, -256, 2048), Vector3.new(-2048, -512, -2048)):ExpandToGrid(4), 4, Enum.Material.Basalt)
I get the error Region cannot be empty. What gives? Of course the region is empty, I am trying to change that. Is :FillRegion() broken?
Your code has all the pieces for this to work properly, but you've defined your region inside out :
Region3.new(Vector3.new(2048, -256, 2048), Vector3.new(-2048, -512, -2048))
Looking at the docs, Region3.new() expects that the first argument is the minimum value and the maximum second, and comes with the warning :
Note that the order of the provided bounds matters: by switching them, the polarity of the Size components will switch. It is possible to create a Region3 with a negative volume.
Swapping these values in the constructor makes your code work just fine :
local resolution = 4
local max = Vector3.new(2048, -256, 2048)
local min = Vector3.new(-2048, -512, -2048)
local targetRegion = Region3.new(min, max)
local expandedRegion = targetRegion:ExpandToGrid(resolution)
workspace.Terrain:FillRegion(expandedRegion, resolution, Enum.Material.Basalt)

Specman coverage: Is there a way to define ranges using variable?

I have comp_value that gets values between 1 .. 100.
In addition I have an input variable period (of the same range). I need to cover 2 ranges of comp_values: [1..period] and [period+1 .. 100]. Something like this:
cover some_event_e is {
item period using no_collect;
item comp_val using no_collect,
ranges = {
range([1..period], "Smaller_than_period");
range([period+1..100], "Bigger_than_period");
};
};
(The code causes compilation error since no variable can be written inside range).
Is there a way to collect the coverage?
Thank you for your help.
Ranges must be constant.
But if I understood your intent correctly, you can define new items like
cover some_event_e is {
item smaller_or_equal_than_period: bool = (comp_val in [1..period]) using
ignore = (not smaller_or_equal_than_period);
item greater_than_period: bool = (comp_val in [(min(100,period+1)..100]) using
ignore = (not greater_than_period);
};
Assuming period is always in [1..100].

Assigning a previous fieldvalue to a field in the next record

I am working on a loan amortization schedule using Access, I have created the following tables:
tblMembers - autoMemberID|txtLN|txtFN|etc
tblLoans - autoLoanID|numMemberID|etc
tblSchedules -autoScheduleID|numLoanID|numPayment#|datDue|dblBegin|...|dblEnd
tblPayments - autoPaymID|numLoanID|curAmtPaid|datPaidDate
and forms:
frmLoans - autoLoanID|etc
sbfSchedules - numPaymID|datDue|dblBegin|...|dblEnd
sbfPayments - dblAmount|datPaid
I have been able to generate the schedule (using DAO recordset) clicking a btnRepaymentSchedule the challenge is when I click a btnAddPayment still on the sbfSchedules, I want the value of the dblEnd field to be the value of the next record dblBegin field! I have tried using
dlookup(txtBeginBalance = Dlookup("EndBalance", _
"Schedules","[ScheduleID] = Form![Schedules]![ScheduleID]-1)
but there is no effect but if I use
txtBeginBalance = txtEndBalance
the value of txtEndBalance is assigned to the value of txtBeginBalance of the same record (want next record).
Secondly, how can I set focus to the next record if a contro(txtAmountPaid) is not null on clicking the btnAddPayment or assigning the value of a calculation when the control is 0 or null ?
Thanks
Have you tried a recordset instead of a (much slower) dlookup? Something like...
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("select [EndBalance] from [Schedules] where [ScheduleID] = " & Form!Schedules!ScheduleID - 1)
If Not rs.EOF Then
Forms!Schedules!DblBegin = rs!EndBalance
End If
rs.Close
Set rs = Nothing
...for the second q:
If Not IsNull(Forms!Schedules!txtAmountPaid) then
DoCmd.GoToRecord , , acNext
Else
Forms!Schedules!Your_Field_Name = calculation_goes_here
End If

set Datagirdviewcombobox column value in Vb.net

I have datagrid with two datagridviewcombo column, one column is dynamic fill and one has fixed hardcoded values.
The problem is I can't set the value of dynamic GridViewComboBox, when I try to set it generates continues errors.
System.FormateException: DataGridViewComboBoxCell Value is not valid.
My code to load the grid is
Dim dt As DataTable
dt = GetDataTable("Select valuecol,displayCol From mytable") 'GetDataTable gives me datatable
cmbAntibiotics.DataSource = dt
cmbAntibiotics.DisplayMember = "Antibiotics"
cmbAntibiotics.ValueMember = "AntibioticsID"
Dim Index As Integer
Dim dgr As DataGridViewRow
For Each dr As DataRow In dtFromDB.Rows 'This datatable is filled with database
Index = dtFromDB.Rows.Count - 1
GRDAntimicrobials.Rows.Add()
GRDAntimicrobials.Rows(Index).Cells("cmbAntibiotics").Value = dr("AntibioticsID").ToString 'At this point it shows value (1,2,3) rather then showing its display members
GRDAntimicrobials.Rows(Index).Cells("AntibioticsStatus").Value = dr("AntibioticsStatus").ToString
Next
Pls help with me
It seems like you're trying to assign the value to whatever there is on the cell rather than instantiate the object that resides in the cell and then assign its value. I would try something like this:
Dim vComboBoxColumn As DropDownList = DirectCast(GRDAntimicrobials.Rows(index).Cells("cmbAntibiotics"))
vComboBoxColumn.Value = dr("AntibioticsStatus").ToString