can anyone help me to solve this error. Got error at line
wtp.Add(New WaterTreament() With {.position = positionName, .value = Convert.ToDouble(sqlRs2("value").ToString()), .timestamp = sqlRs2("dtimestamp").ToString()})
Here's the code
Dim wtp As New List(Of WaterTreament)()
sqlRs2.Open(strSQL2, objConn2)
If Not sqlRs2.EOF Then
Dim positionName = sqlRs2("position").ToString()
If (positionName = "60") Then
positionName = "CHLORINE"
ElseIf (positionName = "61") Then
positionName = "TURBIDITY"
ElseIf (positionName = "62") Then
positionName = "PH"
ElseIf (positionName = "63") Then
positionName = "FLORIDE"
End If
wtp.Add(New WaterTreament() With {.position = positionName, .value = Convert.ToDouble(sqlRs2("value").ToString()), .timestamp = sqlRs2("dtimestamp").ToString()})
End If
Well, sometimes it is REALLY a lot better to just write out a few extra lines of code. I mean, fancy pants can be cool, and great, but often a few extra lines of code is a bettter approach.
So, say try this:
dim MyWaterTreat as new WaterTrament
MyWaterTreat.position = positionName
MyWaterTreat.value = Convert.ToDouble(sqlRs2("Value).ToString())
MyWaterTreat.TimeStamp = sqlRs2("dtimesamp").ToString()
wtp.Add(MyWaterTreat)
You get much nicer intel-sense, and probably save a pot of coffee in the debugging process anyway.
So, sometimes, you better off to write a few extra lines of code. And with VS, then say ctr-d to duplicate the previous line? You might result in a bit more code but you the developer did not actually have to type in that code, or all that much of it.
So, create a new instance of the class. Add the values along with GREAT nice intel-sense, and then add that new object to the list.
Better yet, you also tend to get intel-sense for miss matched data types.
Related
I am using OpenOffice Calc spreadsheet formulas with psuedo-random numbers to generate arrays of arithmetic problems which I can easily update to creating new worksheets (I'm a teacher)
Problems are output as formula mark-ups in string form. OOo Math formulas use these string commands typed into the editor to display nicely formatted maths expressions.
I can do this next step manually:
1) go to source cell and copy string mark-up to clipboard
2) select target cell and clear existing contents and objects
3) create new Math object anchored to target cell
4) open Math editor window and paste in mark-up string
5) exit Math editor window and return cursor to source cell
Result: a nice maths expression of given arithmetic problem.
I need to be able to do this for entire columns of source cells on various sheets.
...even better, to then add a listener to dynamically update as sources are updated.
I found code here: Cell content inside formula that achieves this for a fixed pair of cells, but despite all my best efforts, I have had to admit defeat - generalising this code is simply beyond my expertise!
The absolute ideal would be a macro function that I could call like a spreadsheet function; with input arguments (sourceCell, targetCell, listenerON/OFF) that could run the above algorithm and dynamically update if required.
Can anybody help me? A solution like this, or any kind of workaround would be immensely helpful.
UPDATE 2016/10/27
Thank you Jim K, that did work, but use of the dispacher comes with a whole host of difficulties I hadn't foreseen.
I just found Charlie Young's post in the OpenOffice forum which makes use of the API. I have included my adaptation of his code below.
Can anybody help me to integrate it into a function in a similar way as I've described? I don't know how to solve placement of the Math object in to the target cell.
The API code is great as it will create a new Math object each time the code is updated. Existing ones do need to be deleted though.
I think the limitation of not being able to delete existing objects from within a function is going to persist. Would this be the case even if done by a subroutine called by the function?
function InsertFormula(paraFromCell, paraToCell)
Dim oDoc As Object
Dim oSheet As Object
Dim oShape As Object
oDoc = ThisComponent
oSheet = oDoc.Sheets(0)
oShape = oDoc.createInstance("com.sun.star.drawing.OLE2Shape")
oShape.CLSID = "078B7ABA-54FC-457F-8551-6147e776a997"
oSheet.Drawpage.Add(oShape)
oShape.Model.Formula = paraFromCell
oShape.setSize(oShape.OriginalSize)
end function
NEXT UPDATE
I've been managing to solve my own problems quite quickly now...
I've decided to go with a sub, not a function, so I can access the sheet to delete existing objects. Code is attached - Source cells are in Column C and target cells in matching rows of Column A. So far I am only able to send objects to $A$1.
How do I anchor each new object to a specific cell?
REM ***** BASIC *****
Sub InsertThisFormula
Dim oDoc As Object
Dim oSheet As Object
Dim oShape As Object
Dim sourceCell As Object
Dim targetCell As Object
oDoc = ThisComponent
oSheet = oDoc.Sheets(1)
Dim n As Integer
n = 1 'number of rows of formulas
for i = 0 To n-1
rem loop through cells
sourceCell = oSheet.getCellByPosition(2, i)
targetCell = oSheet.getCellByPosition(0, i)
rem clear target cell object/s
targetCell.ClearContents(128)
oShape = oDoc.createInstance("com.sun.star.drawing.OLE2Shape")
oShape.CLSID = "078B7ABA-54FC-457F-8551-6147e776a997"
oSheet.Drawpage.Add(oShape)
oShape.Model.Formula = sourceCell.string
oShape.setSize(oShape.OriginalSize)
Next i
End Sub
Starting from Mifeet's example, add this to My Macros:
rem ----------------------------------------------------------------------
rem Creates a math formula from text
Function InsertFormulaFromCell(paramCellFrom, paramCellTo)
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem go to cell containing markup and copy it
dim fromCellArgs(0) as new com.sun.star.beans.PropertyValue
fromCellArgs(0).Name = "ToPoint"
fromCellArgs(0).Value = paramCellFrom
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, fromCellArgs())
dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())
rem go to cell where I want the formula displayed
dim toCellArgs(0) as new com.sun.star.beans.PropertyValue
toCellArgs(0).Name = "ToPoint"
toCellArgs(0).Value = paramCellTo
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, toCellArgs())
rem open Star.Math
oDesk = createUnoService ("com.sun.star.frame.Desktop")
dispatcher.executeDispatch(document, ".uno:InsertObjectStarMath", "", 0, Array())
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem paste clipboard using Array() as place-holder for variable name
dispatcher.executeDispatch(document, ".uno:Paste", "", 0, Array())
rem exit Star.Math
dispatcher.executeDispatch( _
document, ".uno:TerminateInplaceActivation", "", 0, Array())
InsertFormulaFromCell = "Math Formula updated " & Now()
End Function
To run it, put this formula in cell C5:
=INSERTFORMULAFROMCELL("$C$3","$C$20")
Now when the values get updated, it creates another formula.
Note: I could not get the .uno:Delete section of Mifeet's code to work, perhaps because functions are not supposed to access other cells. This may require manually deleting the formulas before creating new ones.
(Posted solution on behalf of the OP).
This is now solved. After a lot of searching, I found what I needed! Simple really. Future improvements might be to resize cells appropriately. Happy for now. Thanks to Jim K and the rest of the Stack Overflow community!
Complete macro below:
REM ***** BASIC *****
Sub InsertThisFormula
Dim oDoc As Object
Dim oSheet As Object
Dim oShape As Object
Dim sourceCell As Object
Dim targetCell As Object
oDoc = ThisComponent
oSheet = oDoc.Sheets(1)
Dim n As Integer
n = 6 'number of rows of formulas
for i = 0 To n-1
rem loop through cells
sourceCell = oSheet.getCellByPosition(2, i)
targetCell = oSheet.getCellByPosition(3, i)
rem clear target cell object/s
targetCell.ClearContents(128)
oShape = oDoc.createInstance("com.sun.star.drawing.OLE2Shape")
oShape.CLSID = "078B7ABA-54FC-457F-8551-6147e776a997"
oSheet.Drawpage.Add(oShape)
oShape.Model.Formula = sourceCell.string
oShape.setSize(oShape.OriginalSize)
oShape.Anchor = targetCell
oShape.MoveProtect = True
Next i
End Sub
So here's the situation. I tried to use a quick way to get info from my database and put it in a table. Apparently, if I ask too much info from the following select, it just won't work.
<%
var myConn, myRec, refCo, myCmd;
refCo = Request.querystring("refC");
Response.Write(refCo);
myConn = new ActiveXObject("ADODB.Connection");
myRec = new ActiveXObject("ADODB.Recordset");
myCmd = new ActiveXObject("ADODB.Command");
myConn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/inetpub/wwwroot/unsite/database/world2003.mdb;");
/* myCmd.ActiveConnection = myConn;
myCmd.CommandText = "SELECT NameCountry, Capital, Language, Area, Population, Descripton FROM COUNTRIES WHERE NumCountry = " + refCo";
myCmd.Execute(); */
myRec.Open("SELECT NameCountry, Capital, Language, Area, Population, Descripton FROM COUNTRIES WHERE NumCountry = " + refCo,myConn);%>
See the myRec.Open? It does not allow me to go pass Capital. It just won't. I figured that maybe it was too much and to go with the longer form, meaning a ADODB Command. Say I take off the comments and use myCmd, it won't work at all. Can anyone help me?
It is not because of the number of items in the select list, but because you have a reserved word Language as a field name. You could rename the field to something else or escape it as [Language].
Change your query to:SELECT NameCountry, Capital, [Language], Area, Population, Descripton FROM COUNTRIES WHERE NumCountry = " + refCo and it should work
See this: List of reserved words in Jet 4.0
I'm new to classic asp and I'm trying to figure out this simple if else statement.
For some reason it's just recognizing person 2 and not even trying person 1?
Any idea on how to fix? Thanks
This is my code:
<%
Dim GetPath
GetPath = request.ServerVariables("URL") & query_string
Dim page
page = "/products/dowlex/index.htm"
if GetPath = page then
varrecipient = "email1#email.com"
Response.Write("*Path = " & GetPath)
Response.Write("Person 1")
else
varrecipient = "email2#email.com"
Response.Write("*Path = " & GetPath)
Response.Write("Person 2")
end if
varFormName = "Contact"
varRHBusinessUnit = "businessname"
varLanguage = "ENGLISH"
varCourtesyResponse = "Y"
varRedirect = "#noredir?formRun=true"
varSubject = "Ask an Expert Form"
%>
I would compare the two strings based on the same case...
if UCase(GetPath) = UCase(page) then
And of course, if query_string ever has a value, then the 1st case will never be true.
The formatting of your statement is fine. If... Then... Else... End if.
I would do a Response.Write("GetPath") to see if you are getting back, what you think you should be.
I have a couple thoughts.
1) Can you use Response.Write to display what's in "GetPath" before the if statement? That might help you see what's going wrong!
2) Try changing the variable names. The editor is making "GetPath" blue, as though it's a reserved word. That might be messing things up.
I'm sorry guys, I messed up a small code and thats why it wasn't working.
I forgot to complete the full path of the site. Thanks for all your help and suggestions!
*Path = /plasticpipes/eu/products/dowlex/index.htm
*Page = /products/dowlex/index.htm
is there a way of calling a specific list of lists without having to check (or loop) them all?
it is easier to understand with an example....
lets say
callList(5).key = "1234"
callList(5).callOpened = "11/26/13"
now i want to do something like
textbox_callOpened.text = callList(where key = "1234").callOpened
i also need to know what index that was at for there are many more items that i need to output too.
You can use LINQ. Add Imports System.Linq at top of the file and use First method with lambda expression as a predicate to get what you need:
' that gives you item matching your predicate '
Dim item = callList.First(Function(x) x.Key = "1234")
' you can use it to set the property '
textbox_callOpened.text = item.callOpened
pseudo code, didn't test but should work
dim something = callList.firstordefault(function(d) d.key = "1234")
if something is not nothing then
textbox_callOpened.text = something.callOpened
else
'cant find an element with key 1234
end if
I'm attempt to commit mostly all new objects to the database, apart from the user. I'm new to entity framework and im not sure how to combat this error.
Error on line _orderDetail.CalenderItems.Add(_newCalendarItem):
The object could not be added or attached because its EntityReference has an EntityKey property value that does not match the EntityKey for this object.
Code:
_db.Orders.AddObject(_order)
For Each n In _namelist
_db.Names.AddObject(n)
Next
For Each n In _namelist
For i As Integer = 1 To _copies
Dim _orderDetail As New OrderDetail
_db.OrderDetails.AddObject(_orderDetail)
_orderDetail.Name = n
_orderDetail.Order = _order
For Each c In _calendarItems
Dim _newCalendarItem As New CalenderItem
_newCalendarItem.Image = c.Image
_newCalendarItem.YearMonth = c.YearMonth
_orderDetail.CalenderItems.Add(_newCalendarItem)
Next
Next
Next
_db.SaveChanges()
I believe I need to add add an entity reference but I'm not sure how. Can anyone point me in the right direction
As dnndeveloper says, your answer is ObjectContext.CreateObject<T>.
So you're gonna want -
Dim ci = _db.CreateObject(Of CalenderItem)()
ci.OrderDetail = _orderDetail
ci.Image = c.image
ci.YearMonth = c.YearMonth
_orderDetail.CalenderItems.Add(ci)
or something along those lines. I've run into this issue a couple of times and this has worked so far.
HTH
Instead of creating a "new calendaritem" you should use _db.OrderDetails.CalendarItem.New() etc... either that or set _newCalendarItem.EntityKey to null.