|
Get rid of the Const declarations.
Just do this:
Sub Logic()
a=2
b=3
c=5
If a + b = c Then
WScript.Echo(c)
End If
End Sub
|
|
|
|
|
But I am still getting the same error
|
|
|
|
|
OK. This is EXACTLY the code I put into a .vbs file and it works. I think you're missing a couple of characters in your version, possibly because you think they're insignificant, but they're not. Any comments should be denoted by an ' character and not \\ or //
Logic
Sub Logic()
a=2
b=3
c=5
If a + b = c Then
WScript.Echo(c)
End If
End Sub
|
|
|
|
|
Hello
VS 2005
I wondering what is the best method to synchronise data on a local client in xml form to a central database.
The dataset will be filled by the web service returning a dataset from the central database.
<code>
ds = ws.GetIncidents()
</code>
I only have one table to update and the client has to be used offline.
Once the dataset has this data, I write the schema and xml. Now the client can use this xml to update, add, and delete incidents.
<code>
ds.writeXMLSchema(path)
ds.writeXML(path, XmlWriteMode.DiffGram) 'DiffGram used for tracking updates
</code>
So I am make all my updates and write those changes to the xml file.
example.
<code>
Dim dr As DataRow
dr = ds.Tables(0).NewRow()
dr("Company") = Me.cboCustomer.Text
dr("Contact") = Me.cboContact.Text
dr("PhoneNo") = Me.txtPhone.Text
ds.Tables(0).Rows.Add(dr)
ds.AcceptChanges() 'Question - is acceptChanges needed before the new row is written to the xml file.
ds.WriteXmlSchema(incidentXSD)
ds.WriteXml(incidentXML, XmlWriteMode.DiffGram)
</code>
'For getting the changes - read in the xml file
<code>
ds.ReadXML(path, XmlReadMode.DiffGram)
IF(ds.HasChanges)THEN
dim dsChanges as new Dataset()
dsChanges = ds.GetChanges()
End IF
</code>
So dsChanges now has new changes.
This is the problem I am having problem with, as the central dataset could have deleted a row. And my client might have a modified
that row. How would I handle that sort of conflict, as the row would not exist on the central database?
Another problem I would send my dsChanges to the central database using the web service. But how would I write the code to update
the central database with my changes?
'My code for the web service to update the central database and synchronise the data
<code>
'Update the central database and return the updated dataset
<WebMethod()> _
Public Function SynchroniseChanges(ByVal dsChanges As DataSet) As DataSet
Dim cmd As New SqlCommand()
Dim da As New SqlDataAdapter()
Dim ds As New DataSet
Try
Me.openConnection()
cmd.Connection = cnn
cmd.CommandType = CommandType.Text
cmd.CommandText = "SELECT * FROM Incident"
da.SelectCommand = cmd
da.Fill(ds, "Incident")
dsChanges.Merge(ds, True, MissingSchemaAction.Add)
'How would I get ds to update the central database
'Once all changes are made to the database return the updated dataset
Return ds
Catch ex As Exception
Console.WriteLine(ex.Message)
Finally
cnn.Close()
End Try
Return Nothing
End Function
</code>
Any suggestions to the last to points would be most helpfull.
Many thanks,
Steve
|
|
|
|
|
steve_rm wrote: This is the problem I am having problem with, as the central dataset could have deleted a row. And my client might have a modified
that row. How would I handle that sort of conflict, as the row would not exist on the central database?
That is something that is defined by your business process. We can't tell you how it should be handled, other than the results in the database and in the off-line data have to reflect whatever your business rules dictate happens in this situation.
steve_rm wrote: Another problem I would send my dsChanges to the central database using the web service. But how would I write the code to update
the central database with my changes?
Since you've already written all of this without considering this synchronization in the design of your app (HUGE mistake!) I'd probably start with only sending the updates one at a time, for each record in the offline database. You'd have to send the record to the webservice, and the webservice would probably compare the modified date/time stamp of the record to the one in the database and take any appropriate action based on what's found. If the date/time stamp of the client record is newer, then the database should be updated. If the database date/time stamp is newer, well, that result is up to your business rules again...
From the looks of things, your database wasn't setup to handle having it's data stored and modified off-line. You've got a bunch of work to do...
Oh! SELECT statements like this:
SELECT * FROM Incident
are a disaster, just waiting to happen. It's a much better practice to specify the column names, even if it is all the columns currently in the table.
As for other options to synchronize an offline copy of the data, you might want to take a look at a bunch of different options[^].
|
|
|
|
|
I am writing in VB6
I have a "shell" script in my code that runs a small exe conversion program.
Shell "my_exe.exe"
I want to pause the subsequent code until this program has time to finishes
I have put in a loop
A = 100000000
Do While A > 0
A = A - 1
Loop
But this is really slow.
Does anyone know a better way to code this?
|
|
|
|
|
A little Google goes a long way toward finding a solution[^] to the problem.
VB6 does not have the ability to do this on its own. You have to use the Win32 API to do it.
|
|
|
|
|
Thanks the following code did what I was looking for
DIM My_Shell
Set My_Shell = CreateObject("WScript.Shell")
My_Shell.Run "my_exe.exe"
|
|
|
|
|
and sometimes people still need to ask as they havent got the correct phrase in the google search box
i.e.
vb6 wait for process to exit
would not have been my first choice for a search phrase.
Martin
life is a bowl of cherries
go on take a byte
|
|
|
|
|
And knowing how to do research is the most important skill you can have doing development work.
|
|
|
|
|
ah if only there was a course that told me to use
process instead of application or program - sigh!!
Martin
life is a bowl of cherries
go on take a byte
|
|
|
|
|
I did & it loaded fine. My problem is, none of the controls to change [select voice],[pitch],[speed],&[volume] had any affect on the audio output. What am I doing wrong?
Robert, still trying
|
|
|
|
|
Your best source of information is going to be the manufacturer of the component.
It's very unlikely anyone who frequents CP and answers questions is going to have any knowledge of such a narrow-market product. Though it looks like it wraps MS Speech API 4.0[^].
|
|
|
|
|
Greetings all.
I've made a service which creates an Excel workbook automatically using the Excel COM object.
I have however got a problem that when I try to enter a formula containing the sheet names to sum across all sheets that the service crashes with a "Exception from HRESULT: 0x800A03EC" error and I'm at my wits ends right now.
I know the formula is correct, because I can copy it from the code and past it into the workbook afterwards and it runs fine, but when trying to do so automatically - it fails.
I create a cell range for the cell I want to write this formula in, and use the
"Formula" property to set the value, and here it crashes.
I've made other formulas without issues, and if I do not contain sheetnames, I can write the formula easily enough (I substituted my SUM for a SUM(1+1)) in the relevant cellrange.
So the issue is solely with a formula containing sheet names for me.
Has anybody else experienced something similar, and possible have a solution or a heads up where to go for one?
---------------------------
127.0.0.1 - Sweet 127.0.0.1
|
|
|
|
|
It looks like that's a nice "generic" error returned by Excel when there is a problem with just about anything using the automation model.
What does the code look like that's setting this formula?
|
|
|
|
|
The code is something along this line (simplified to avoid writing unnecessary function call et al)
myExcelObject.CreateRange("myCellRange")
myExcelObject.CellRange.Formula = "=SUM('SheetName'!Cell;'SheetName'!Cell)"
I can post the more exact code if needs be, but this is the gist of it.
As mentioned, I write other formulas without problems, although these do not span multiple sheets - including array formulas - so there can't really be much at fault with my base code. The problem seems to lie somewhat deeper then just the normal issues, which is why I turned to this forum.
I was thinking the issue might be connected to the fact that I need to "cheat" Excel to think it is a US-EN system by changing the culture when I create the excel objects needed (Workbook, Sheets etc), and when I then try to write the SheetName's in the formula that it has an localization issue or something.
But if this is the case, then I'm really without much of a hope - it just really annoys me cause I can take the fomula from the code, paste it into the generated Excel document and have it work. I just can't print it out automatically
---------------------------
127.0.0.1 - Sweet 127.0.0.1
|
|
|
|
|
A bit more exact would help, I mean a copy'n'paste of the real thing.
The error that's returned is usually caused by an automation failure. Probably due to the code doing something it's not allowed to do. What your doing by putting the formula in a range of cells is not what your code is doing.
I don't do Office Interop projects, so my experience is very limited.
|
|
|
|
|
With mObjExcel<br />
.CreateRange(.GetExcelColumnName(EnuColumn.UnitPrice + mIntColumnCountFactor) & mIntColRow(intCounter) & ":" & .GetExcelColumnName(EnuColumn.UnitPrice + mIntColumnCountFactor) & mIntColRow(intCounter), mStrSheetNames(intCounter))<br />
.CellRange.NumberFormat = "#.##0"<br />
.CellRange.Formula = "=SUM(" & strFormular & ")"<br />
.CellRange.BorderAround(Excel.XlLineStyle.xlContinuous, Excel.XlBorderWeight.xlMedium, , mObjBlack.ToInteger)<br />
End With
The "GetExcelColumnName" is a function which just returns the Excel Column name such as A1, B2 based on a column and row number. Nothing special - just one I made to help myself.
The strFormula variable is the formula mentioned which looks like 'Sheetname!Cell;Sheetname!Cell' and is build dynamically based on which actual sheetnames and cells are used.
The formula works when I copy it into the generated excel document so there is not a problem with the formula as such. Just the generation of it automatically
Inside my mObjExcel the CreateRange looks like
<br />
Friend Sub CreateRange(ByVal range As Object, ByVal strSheetName As String)<br />
SetCultureFixStart() ''Changes the current Culture to en-US, casue otherwise excel automation crashes<br />
If Not mObjCells Is Nothing Then ReleaseComObject(mObjCells)''cleans up COM objects which might linger in memory<br />
mObjCells = Nothing ''cleans up COM objects which might linger in memory<br />
System.GC.Collect() ''cleans up COM objects which might linger in memory<br />
mObjCells = mObjSheets(strSheetName).Range(range).Cells<br />
SetCultureFixEnd() ''sets culture back<br />
End Sub
And CellRange is just a property which returns my mObjCells (which is an Excel.Range).
What strikes me as most annoying is that the above code works when I use 1+1 in the formula instead of Sheetnames!cell, or when I post out more complex formulas, even .FormulaArray work.
So basically so far, I've been able to do all I wanted to, except use Sheetnames in a formula :/
Thanks so far for the feedback/time.
---------------------------
127.0.0.1 - Sweet 127.0.0.1
|
|
|
|
|
I've made a much more simple example which also fails:
mObjExcel = New Excel.Application
mObjWorkBooks = mObjExcel.Workbooks
mObjWorkBook = mObjWorkBooks.Add
mObjSheets = mObjWorkBook.Worksheets
If mObjSheets.Count > 0 Then
For i As Integer = mObjSheets.Count To 2 Step -1
mObjSheet = mObjSheets.Item(i)
mObjSheet.Delete()
Next
mObjSheet = mObjSheets.Item(1)
Else
mObjSheet = mObjSheets.Add
End If
mObjSheet.Name = "A"
mObjSheet.Range("A1").Value = "1"
mObjSheet = mObjSheets.Add()
mObjSheet.Name = "B"
mObjSheet.Range("A1").Value = "1"
mObjSheet.Range("A2").Formula = "=SUM(A1;A!A1)"
This fails, but if I substitute the formula for =SUM(1+1) it writes correct.
The formula is taken directly from what Excel wrote when I made the SUM in there.
|
|
|
|
|
I found a workaround which only confirms my suspecision that it must be something culture specific issue.
I could instead of using a SUM formula add the cells together - and I was able to do this with the sheetnames in the addition, so instead of "SUM" I use "=SheetName!Cell+SheetName!Cell ...." and that looks to work when printed out as a .Value.
Wheee.
Thanks for the help otherwise
|
|
|
|
|
Hmmm...very weird. I wouldn't have thought that the culture would affect the sheetname.
|
|
|
|
|
I have no Excel automation experience, but maybe this idea could help:
you could enter the formula in Excel manually, then use automation to see how it looks...
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
The formula works, so that one is not a problem. I just can't generate the document automatically with this formula - but I can copy it into the document after generation where it would work.
---------------------------
127.0.0.1 - Sweet 127.0.0.1
|
|
|
|
|
I have a datagrid when i click on it at the starting of a row the whole row gets selected and the
datagrid.Columns(i).Text will give each column's text individually.
Even when i click on a perticular column of any row the text in that perticular column gets selected. can i get that perticular text at runtime.
i mean i want to get the text of the perticular cell(x,y) on which i click.
KIRAN PINJARLA
|
|
|
|
|
This code doesn't make sense because the DataGrid class (Windows Forms) doesn't have a Columns collection.
The ASP.NET DataGrid does have a Columns collection.
So which is it? The Windows Forms DataGrid or the ASP.NET (Web Forms) DataGrid in the .NET Framework 1.x (Visual Studio 2002 and 2003)?? Or are you really using the DataGridView class in the .NET 2.0 (Visual Studio 2005)?
|
|
|
|