Below is some vbscript that populates a field called Lot. At the moment when I run this the Lot field is displaying the ManualLot field as 123456.000000.
Does anyone know how I can change the code below to make 123456.000000 just 0000123456? So it removes the .000000 and starts with 0000 instead.
Function ManualLot_OnAfterChange()
If Backflushing.CodeObject.Quantity < 0 Then
Backflushing.CodeObject.Lot = Backflushing.CodeObject.ManualLot
Else
If Backflushing.CodeObject.Quantity > 0 Then
Backflushing.CodeObject.Lot = 0
End If
End If
End Function
You could use Split() get the value to the left of the decimal, and then use Left() to stick some zeros in front of it.
'how long the number should be
testLength=10
'The number we are changing
test="12345.00000"
'split(test, ".")(0) will get us the values to the left of the decimal
test=LEFT("000000000000", testLength-len(split(test, ".")(0))) & split(test, ".")(0)
msgbox(test)
Backflushing.CodeObject.Lot = RTrim (Backflushing.CodeObject.ManualLot)
Fixed it for me. Thanks for the help though JNevil got me on right track.
Related
I am trying to automate a sheet tag with a Diesel expression in AutoCad.
This gets me the twelfth character in the drawing name. But as soon as I get to sheet 10 this will say its sheet 0.
$(substr,$(getvar,dwgname),12,1)
Does anyone know a way to get an If statement to see if the eleventh character is a 0 then run the above code else run $(substr,$(getvar,dwgname),11,2)
This is something i have tried.
$(IF,substr,$(getvar,dwgname),11,1)="0"$(substr,$(getvar,dwgname),11,2,substr,$(getvar,dwgname),12,1)
This appears to be similar to excel formulas. Thanks for any help.
The format for the Diesel if statement is:
$(if, expr, dotrue [, dofalse])
If the expr is nonzero, it evaluates and returns dotrue.
You seem to have a lot more going on in your sample. Do the full evaluation (does the 11th character equal 0 in the expr portion and then set your returns, the false portion is optional and can be omitted.
Here is the Diesel expression i got working for auto sheet no. in autocad fields.
$(if,$(substr,$(getvar,dwgname),11,1)"0",$(substr,$(getvar,dwgname),11,2),$(substr,$(getvar,dwgname),12,1))
$(if,$(substr,$(getvar,dwgname),11,1)"0" = Does character 11 = 0
,$(substr,$(getvar,dwgname),11,2) = if no then take character 11 and the next char.
,$(substr,$(getvar,dwgname),12,1)) = if char 11 is = to 0 then take only char 11.
I use two fields in my autocad border. One for the filename without the sheet no and this one for only the sheet number.
Example filename: A150225_S001.dwg
$(substr,$(getvar,dwgname),1, 7) = Use char from position 1 to 7. "A150225"
$(if,$(substr,$(getvar,dwgname),11,1)"0",$(substr,$(getvar,dwgname),11,2),$(substr,$(getvar,dwgname),12,1)) = Use sheet no. at end of filename string. "1"
Hope this helps anyone looking to do something similar.
I have an order number which is character 10 positions.
I would like to know where the leading blanks end. Only blanks.
So if the number is
' 012345' I want 012345 - Can I do this in RPG? I have tried some FREE codes
but have trouble getting to work in general. So I prefer the old way
or Free is ok if we must.
So what i need to know is, how many positions of the 10 position field are having data? so if the data is 012345 this means 6 positions are filled and 4 are blanks.
Use %scan to locate the blank.
dcl-s source char(10) inz('12345');
dcl-s pos zoned(5);
pos = %scan(' ':source) - 1;
*inlr = *on;
After the eval pos = 5.
If you want to deal with the value without leading blanks, you can use %trim or %trimL. The former will trim spaces from the front and end. The latter will only trim spaces from the front (left).
newOrder = %trimL( originalOrder );
Although your example is a bit odd. Either you typo'd what you want (two 3's?) or if you really do want to insert a 3, then that would require more work. Let me know.
Edit: Maybe this logic better answers what you're looking to do.
To count the number of non-blanks, you can do this:
valueCount = %len( %trim( originalOrder ) );
And if you need to know the number of blanks instead, it's simply:
blankCount = %len( originalOrder ) - %len( %trim( originalOrder ) );
I hope that answers your question.
You can use XLATE to replace all blanks in your string with zeros
I have MATLAB set to record three webcams at the same time. I want to capture and save each feed to a file and automatically increment it the file name, it will be replaced by experiment_0001.avi, followed by experiment_0002.avi, etc.
My code looks like this at the moment
set(vid1,'LoggingMode','disk');
set(vid2,'LoggingMode','disk');
avi1 = VideoWriter('X:\ABC\Data Collection\Presentations\Correct\ExperimentA_002.AVI');
avi2 = VideoWriter('X:\ABC\Data Collection\Presentations\Correct\ExperimentB_002.AVI');
set(vid1,'DiskLogger',avi1);
set(vid2,'DiskLogger',avi2);
and I am incrementing the 002 each time.
Any thoughts on how to implement this efficiently?
Thanks.
dont forget matlab has some roots to C programming language. That means things like sprintf will work
so since you are printing out an integer value zero padded to 3 spaces you would need something like this sprintf('%03d',n) then % means there is a value to print that isn't text. 0 means zero pad on the left, 3 means pad to 3 digits, d means the number itself is an integer
just use sprintf in place of a string. the s means String print formatted. so it will output a string. here is an idea of what you might do
set(vid1,'LoggingMode','disk');
set(vid2,'LoggingMode','disk');
for (n=1:2:max_num_captures)
avi1 = VideoWriter(sprintf('X:\ABC\Data Collection\Presentations\Correct\ExperimentA_%03d.AVI',n));
avi2 = VideoWriter(sprintf('X:\ABC\Data Collection\Presentations\Correct\ExperimentB_002.AVI',n));
set(vid1,'DiskLogger',avi1);
set(vid2,'DiskLogger',avi2);
end
I am trying to display a double so it will always have 4 digits after the decimal point. For example, one double would be 0.0182, and another 0.0180. However, my problem occurs when the double ends in 0, which results in truncating the zero and leaving 0.018. I'm trying to add on a zero at the end of my number to fix this, but receiving a syntax error.
Dim minFeature As Double
...
minFeature = Round(minFeature, 4) ' keep only 4 digits of precision. works.
minFeature = CDbl(CStr(minFeature).PadRight(1, "0")) ' add on an extra 0. does not work.
This will return the number as a string and preserve four decimal places.
Format(minFeature, "0.0000")
For more information, see the docs on Format().
I have this code and something odd happening when I'm running it.
I have field number like 101512 up to 101520. I've used LEFT function to get rid of last two digits and keep the 1015. When i runn loop function for the first one it gives me 1015 but for the rest it gives me 101 an it elminates the last digit like this:
d = Split(Request("field"),",")
For i = 1 To UBound(d)
Responce.Write(Left(d(i),4))
Next
Results
1015
101
101
101
...
Does anybody have any idea what is going on?
My guess is that Request("field") may be returning a string like the following:
101520, 101521, 101522
Note the space after each comma. Thus when you apply Left() and print the value to your HTML output you don't notice the space but you only see three digits as the space counted as the first digit
One thing to try to see if this is the case is to change the code to the following:
Left(Trim(d(i)), 4)
That way any spaces around the value are removed before Left() is applied.
Correct way to iterate over "multi value" request item is actually:
For i = 0 To Request("field").Count-1
Response.Write(Request("field").Item(i) & "<br />")
Next
This will iterate the actual values without using split at all..