|
Basically, the string is an if statement.
For example:
if Cost = 20 * Quantity / Discount and Cost = 49 then....
This is an input from user. And i'm trying to parse the string and check the "if" part only.
John
|
|
|
|
|
Let me get this straight... This is your VB.NET code and your trying to do something like this:
'Get some user input and put it in a variable. Then evaluate the expression...
Dim strInput As String = "Cost = 20 * Quantity / Discount and Cost = 49"
EvaluateUserExpression(strInput)
.
.
.
Public Function EvaluateUserExpression(ByVal strExpression As String) As Boolean
If strExpression Then
Return True
Else
Return False
End If
End Function
Now, if I understand you correctly, the Cost, Quantity, and Discount terms are actual variables inside your code. Correct?????
If this is true, then what you want to do can't be done using a simple if statement. You must parse up and validate the expression term-by-term and evaluate it along the way. You would ahve to check to see if the Cost/Quantity/Discount variables exist in your code, handle the equals signs and the operators yourself. You're looking for expression parsing techniques that, if covered in breif, are much too large to be taught over the forums.
Google for 'VB mathematical expression parser' and you'll come up with tons links on various articles, techniques, some source code...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I'm generating charts with dynamic data. My problem is, my default chart options do not save when they are loaded onto another computer.
Can anyone tell me how to dynamically set chart options so that they will generate correctly on other computers?
(Chart type/series type/etc.)
I need to modify the X and Y Axis Scale
I need to modify the Chart Type
And various other chart options as such.
|
|
|
|
|
First, I don't remember ever seeing default chart options anywhere. When you create the Chart sheet, you pick stuff like chart type, data range, axis labels, ... Those are saved with the Chart sheet. Including the X and Y axis scales, chart type, ...
Are you saying that you are generating the Chart sheet from code? Is the workbook being saved AFTER the Chart sheet is made and you make the modifications to it? And when that workbook is loaded on another machine is the code for generating the Chart sheet being re-run? Is the old Chart sheet being deleted first? ...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
You can set the default Chart in chart type options.
I do not create the chart with the wizard, I create it strictly through code.
The workbook never gets deleted... Ever.
Charts are generated dynamically as data is entered. So it is ever changing
But besides that, I did figure it out. I found the options on the web after searching for quite a while.
If anyone is interested in the code, let me know and I will post it.
|
|
|
|
|
Yes, i am intrested, please paste the code.
thanks
|
|
|
|
|
Okay, here you go:
------------------------------------------------------
'***Create a new series for the chart object<br />
Function createSeries()<br />
<br />
Dim DataSource As Range<br />
Dim DataRows As Long<br />
Dim DataCols As Integer<br />
Dim MyNewSrs As series<br />
Dim valArray() As Double<br />
Dim currentChart As String<br />
Dim i As Integer<br />
Dim chartName As String<br />
Dim rowNumber As String<br />
Dim offsetval As Integer<br />
Dim modValue As Integer<br />
Dim tempRows As Integer<br />
<br />
If tempRow = 6 Then<br />
modValue = 6<br />
ElseIf tempRow = 5 Then<br />
modValue = 5<br />
Else<br />
Exit Function<br />
End If<br />
<br />
offsetval = 0<br />
i = 0<br />
<br />
Worksheets("Standards").Select<br />
<br />
'Get selection<br />
Set DataSource = Selection<br />
With DataSource<br />
DataRows = .rows.Count<br />
tempRows = DataRows<br />
DataCols = .Columns.Count<br />
End With<br />
<br />
ReDim valArray(0 To DataRows - 1)<br />
<br />
'save values in an array<br />
While DataRows <> 0<br />
If Len(DataSource(i + 1)) > 2 Then<br />
valArray(i - offsetval) = DataSource(i + 1) / standardValues((i - offsetval) Mod modValue)<br />
Else<br />
offsetval = offsetval + 1<br />
End If<br />
i = i + 1<br />
DataRows = DataRows - 1<br />
Wend<br />
<br />
i = 0<br />
DataRows = tempRows<br />
<br />
'check values to see if they are in range for the chart<br />
While DataRows <> 0<br />
If valArray(i) > 1.2 Then<br />
valArray(i) = 1.2<br />
ElseIf valArray(i) < 0.8 Then<br />
valArray(i) = 0.8<br />
End If<br />
<br />
i = i + 1<br />
DataRows = DataRows - 1<br />
Wend<br />
<br />
Worksheets("Charts").Select<br />
myChart.Select<br />
<br />
chartName = DataSource.Column<br />
chartName = ConvertColumnNumberToLetter(chartName)<br />
<br />
rowNumber = DataSource.Row<br />
<br />
'plot values on the graph<br />
With ActiveChart.SeriesCollection.NewSeries<br />
.Name = (Worksheets("Standards").Range(chartName & "2"))<br />
.Values = valArray<br />
.XValues = Array(0, 1, 2, 3, 4, 5)<br />
End With<br />
<br />
'Format chart to make it look nice<br />
myChart.Activate<br />
ActiveChart.ChartType = xlXYScatter<br />
<br />
<br />
ActiveChart.PlotArea.Select<br />
With Selection.Border<br />
.ColorIndex = 16<br />
.Weight = xlThin<br />
.LineStyle = xlContinuous<br />
End With<br />
With Selection.Interior<br />
.ColorIndex = 2<br />
.PatternColorIndex = 1<br />
.Pattern = xlSolid<br />
End With<br />
ActiveChart.ChartArea.Select<br />
With ActiveChart.Axes(xlCategory)<br />
.HasMajorGridlines = True<br />
.HasMinorGridlines = False<br />
End With<br />
With ActiveChart.Axes(xlValue)<br />
.HasMajorGridlines = True<br />
.HasMinorGridlines = False<br />
End With<br />
ActiveChart.HasLegend = False<br />
ActiveChart.Axes(xlValue).Select<br />
With ActiveChart.Axes(xlValue)<br />
.MinimumScale = 0.8<br />
.MaximumScale = 1.2<br />
.MinorUnitIsAuto = True<br />
.MajorUnitIsAuto = True<br />
.Crosses = xlAutomatic<br />
.ReversePlotOrder = False<br />
.ScaleType = xlLinear<br />
.DisplayUnit = xlNone<br />
End With<br />
Selection.TickLabels.NumberFormat = "0%"<br />
ActiveChart.Axes(xlValue).MajorGridlines.Select<br />
ActiveChart.PlotArea.Select<br />
ActiveChart.Axes(xlCategory).Select<br />
ActiveChart.Axes(xlValue).Select<br />
With ActiveChart.Axes(xlValue)<br />
.MinimumScale = 0.8<br />
.MaximumScale = 1.2<br />
.MinorUnitIsAuto = True<br />
.MajorUnitIsAuto = True<br />
.Crosses = xlCustom<br />
.CrossesAt = 1<br />
.ReversePlotOrder = False<br />
.ScaleType = xlLinear<br />
.DisplayUnit = xlNone<br />
End With<br />
ActiveChart.Axes(xlCategory).Select<br />
With ActiveChart.Axes(xlCategory)<br />
.MinorUnitIsAuto = True<br />
.MajorUnit = 1<br />
.MaximumScale = 5<br />
.MinimumScale = 0<br />
.Crosses = xlAutomatic<br />
.ReversePlotOrder = False<br />
.ScaleType = xlLinear<br />
.DisplayUnit = xlNone<br />
End With<br />
Selection.TickLabels.AutoScaleFont = True<br />
With Selection.TickLabels.Font<br />
.Name = "Arial"<br />
.FontStyle = "Regular"<br />
.Size = 1<br />
.Strikethrough = False<br />
.Superscript = False<br />
.Subscript = False<br />
.OutlineFont = False<br />
.Shadow = False<br />
.Underline = xlUnderlineStyleNone<br />
.ColorIndex = xlAutomatic<br />
.Background = xlAutomatic<br />
End With<br />
ActiveChart.SeriesCollection(1).Select<br />
With Selection.Border<br />
.Weight = xlHairline<br />
.LineStyle = xlNone<br />
End With<br />
With Selection<br />
.MarkerBackgroundColorIndex = 3<br />
.MarkerForegroundColorIndex = 9<br />
.MarkerStyle = xlSquare<br />
.Smooth = False<br />
.MarkerSize = 4<br />
.Shadow = False<br />
End With<br />
<br />
End Function
|
|
|
|
|
Hello to all..
I am doing a program that a time carried out some operations on the pc. ..creates a txt in which contains some info on the procedure...
And here all outcome ok. ...
The problem is that when the file is compiled, I should send it to a server....but to make this I should await that the file is concluded.
Now I wonder: I know that until the end of the procedure the file size is 0 KB and a time concluded, it is immediatly replenished in approximately 300 KB... it's possible to establish (maybe with a loop...), until the file size is equal to 0 KB ---> do ACTION 1; when the same file is DIFFERENT from 0 KB (does not matter myself how much is big. ..) then do ACTION 2......
It is possible in your opinion?
Thanks to all..
Night Soul!!!
|
|
|
|
|
Let me see if I understand you...
You want to monitor the size of a file, and based on its size, you want to determine if it's safe to copy the file to another server and then erase the file and let the other app recreate it.
Correct? It's possible... but a questionable technique.
A better method would be to try and rename the file constantly. If the file is open, the rename will fail. When the rename finally succeed's, you accomplish two things. One, the file is immediately taken out of the way of the other application, freeing it to create another one. Second, you now have exclusive rights to the renamed file because the other applications know nothing of the new name. You are free to do whatever you want with this renamed file, like copy it to a server, and if the server is not available at the time of the copy, store the file locally to be copied up later.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I don't want to make exactly what you mean....
I Try to explain me.....
I must upload a file on a server....but the process that create it use a few minutes to conclude the file....
I try all the way I now...but at a certain point there is an error..."the file is being used from another process"...
I must know exactly when the procedure terminate....
It was for this reason that had thought to do a loop that until the file size is = 0 do ACTION 1, instead when the file is full you do ACTION 2..
Excuse me again for my bad english....but can you understand me now?
I hope....
tynx a lot.....
Night Soul!!!
|
|
|
|
|
What is ACTION1 and ACTION2?
If the file is opened by the process exclusively, there won't be any ACTION on the file until the other process closes it. Just checking the file size is not a good of that. The file sits at zero until the app and the O/S flushes it's buffers, but the app doesn't have to close the file to do that. The file size will rise, but will still be open by the app...
That's why I say you have to try and open the file to determine when it is actually closed by the other app. Until the other app closes it, you WILL get "the file is being used by another process", or an Exception, that you must handle in your code in order to find out when the other process closes the file.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I paste the loop I have in mind...Why it does not work?
Sub LoopSize()
Dim i As Integer
i = 0
Const FILE_SIZE = FILE_PC_INFO
Dim Peso_File As FileInfo
For i = 0 To 0
If FILE_SIZE.Length = 0 Then
Thread.Sleep(3000)
Else
MsgBox("THE FILE IS COMPILED!!!")
Thread.Sleep(3000)
i = i + 1
End If
Next
End Sub ' LoopSize
*** FILE_PC_INFO is myinformationsfile.txt ***
does it help understand me?
Night Soul!!!
|
|
|
|
|
Your loop does not execute. If you need a loop the executes forever, use
Do While True<br />
' check file size here<br />
' ...<br />
' *****<br />
<br />
If FILE_SIZE.Length = 0 Then<br />
Thread.Sleep(3000)<br />
Else<br />
MsgBox("THE FILE IS COMPILED!!!")<br />
Exit Do<br />
End If<br />
Loop
Regards,
Serge (Logic Software, Easy Projects .NET site)
|
|
|
|
|
|
I am working with a 3rd party app that takes focus when it needs to perform certain tasks. The problem with this is if the user presses the ESC key the application needs to be reloaded.
Is there an easy way to disable the ESC key before it takes focus and then re-enable it when focus is returned to my app?
Thanx for all the input...
t
|
|
|
|
|
Easy? No... You'll have to write either a keyboard hook that looks at every keystroke and doesn't pass on the ESC key, or write a Message Filter that implements IMessageFilter to do the same thing.
The keyboard hook is harder to write...
The docs for the MessageFilter starts here[^].
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Dave, excuse me but can you explain me, what a keyboard hook is?
tnx!;)
Night Soul!!!
|
|
|
|
|
A keyboard hook is a function that you write and register with Windows using the SetWindowsHookEx API function. Basically, this function will be called every time the keyboard driver attempts to post a keyboard message to an input queue. You can see every keystroke message before it goes to an application. This function has a responsibility of passing along the data that the driver has given it to the next hook in the chain. (You can have multiple hooks attached, where each hook has to pass the data it receives to the next...)
The cool part is you can manipulate the message data before it's passed to the next hook. Or, if you need to disable certain keys, DON'T pass the data to the next hook. Just return nothing...
I've written hooks to disable the Windows Logo keys, eat certain keystrokes at certain times, and have even had a little fun, like 5 times a second, replace the WM_KEYDOWN message with a different key than was hit... Drives people nuts when they don't know you installed it!
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
thanks for the lesson!!!;)
well done!
Night Soul!!!
|
|
|
|
|
Hi everybody,
I've a simple question to you:
If two or more applications are running, and I want to get a refernece to a specific one, how can I do that
e.x
Two MS Word are running
and I want to GetObject (, "Word.Application"), of course that depends on who runs first.
the question is
How can I get always the application tha I want ?
Thanks in advance.
Carlos Mariano
Carlos Mariano
|
|
|
|
|
Are you saying that you want to retrieve a specific instance of Word that is already running? You can't. There is no way to get a reference to a specific instance of an object. If it's Word that your trying to get, only one copy of it is ever running at any one time. Once you get the reference to Word, you can use the Word object model to pick the document you want from its Documents collection.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
It sounds logic, what about avoiding to run two or more word instances .
Is tit possible ?
Thanks!
Carlos Mariano
|
|
|
|
|
You CAN'T run more than one instance of Word. Word, itself, takes care of this. If you try to open multiple documents at the same time, Word will open just once and load all the documents seperately and manage them. This is what the MDI model (Multiple Document Interface) model is all about.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I know that, word was an example, may be a bad example, but there'a application tha you can run more than once at the same time.
You may want to have multiple mdi application or not ?
the queastion was if you have sutch application is it possible to get one expecifically
Thanks
CM
Carlos Mariano
|
|
|
|
|
In that case, no you can't get a specific instance.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|