I'm creating a game, which will store maps on separate files.
This is done in that file using variables as such:
Public X1Y1 = "idle"
Containing the location and pixel information for my screen drawing engine.
To draw each pixel, I need to cycle through all of these variables.
I wanted to do that as shown, but I can't figure out how to refer to the variables in the map file(eg: X1Y1 or X5Y4), using a variable which stores the name of the variable required (pos).
Dim targetmap As SplashMap = New SplashMap()
For rowcount = 0 To targetmap.xRes Step 1
'for each row on the map
For columncount = 0 To targetmap.yRes Step 1
'place the pixel in each column
Dim pos = "X" & rowcount & "Y" & columncount
PlacePixel(pos, targetmap.'var <- problem, vbNull)
'call engine(Pixel Location, Pixel information stored in var, special control instruction (unused))
Next
Next
Related
I written a VB.Net program that intercept RENDER_PATH and RENDER_TEXT events generated by iText7 module.
I have written a little code to find location of TEXT.
Dim ascent As LineSegment = t.GetAscentLine()
Dim descent As LineSegment = t.GetDescentLine()
Dim initX As Single = descent.GetStartPoint().Get(0)
Dim initY As Single = descent.GetStartPoint().Get(1)
Dim endX As Single = ascent.GetEndPoint().Get(0)
Dim endY As Single = ascent.GetEndPoint().Get(1)
For specific PDF page, all values returned by GetStartPoint() and GetEndPoint() are between 20 and 600.
To find PATH values, I have writte following code
Private Sub RenderPath(render As PathRenderInfo)
For Each sp As Subpath In render.GetPath().GetSubpaths()
Console.WriteLine(render.GetPath().ToString())
For Each segment In sp.GetSegments()
Console.WriteLine(" " & segment.ToString())
Select Case segment.GetType().FullName
Case "iText.Kernel.Geom.Line"
Dim oLine As iText.Kernel.Geom.Line = segment
Dim oList As List(Of Point) = oLine.GetBasePoints()
Dim n = 0
For Each p In oList
Console.WriteLine(" p" & CStr(n) & ".x: " & CStr(oList(n).GetX()))
Console.WriteLine(" p" & CStr(n) & ".y: " & CStr(oList(n).GetY()))
n += 1
Next
Console.WriteLine(" width: " & CStr(oList(0).GetX() - oList(1).GetX()))
Console.WriteLine(" height: " & CStr(oList(0).GetY() - oList(1).GetY()))
Case "iText.Kernel.Geom.BezierCurve"
Case Else
Dim i0 = 0
End Select
Next
Next
End Sub
All location's values returned by GetX() and GetY() functions are now between ... 200 and 6000 !
Why PATH location's values seems to be 10 times greater that TEXT location's values ?
Is that normal or is that a BUG ?
In iText7, what are dimensions of TEXT locations and dimensions of PATH segments ?
In iText7, what are dimensions of TEXT locations and dimensions of PATH segments ?
Indeed, the coordinates returned by TextRenderInfo and those returned by PathRenderInfo differ:
Coordinates returned by TextRenderInfo are given in the default user space coordinates of the given page, i.e. all active transformations are already accounted for.
Coordinates returned by PathRenderInfo, on the other hand, are given in the current user space coordinates - current when the path is constructed and drawn. To transform these coordinates into default user space coordinates, you have to apply the CTM (current transformation matrix) to the path. You can retrieve the CTM using the GetCTM method of the path render info object.
That different render info classes return coordinates in conceptually different coordinate system probably isn't intuitive and should be made clearer.
In case of your document page the CTM appears to be a scaling transformation by a factor of 0.1.
Why does the messagebox show "False"?
Dim images(4, 4) As Image
For rows = 0 To 4
For columns = 0 To 4
images(rows, columns) = My.Resources.kaboom
Next
Next
MessageBox.Show(images(3, 3).Equals(My.Resources.kaboom))
If you look at the code behind the kaboom property, you will see it creates a new object every time.
'''<summary>
''' Looks up a localized resource of type System.Drawing.Bitmap.
'''</summary>
Friend ReadOnly Property kaboom() As System.Drawing.Bitmap
Get
Dim obj As Object = ResourceManager.GetObject("kaboom", resourceCulture)
Return CType(obj,System.Drawing.Bitmap)
End Get
End Property
If you keep a reference to one object, it will be equal to true. It might also be faster since it doesn't need to create a new object.
Dim kaboom As Image = My.Resources.kaboom
Dim images(4, 4) As Image
For rows = 0 To 4
For columns = 0 To 4
images(rows, columns) = kaboom
Next
Next
MessageBox.Show(images(3, 3).Equals(kaboom))
Maybe you are already planning on doing this but here is a suggestion. If you are creating some sort of game, separate the display from the game logic. This mean, save the type of tile instead of the image and compare that. Later, you can add a bunch of different properties to a tile.
Const TYPE_KABOOM As Integer = 1
Dim tileType(4, 4) As Integer
For rows = 0 To 4
For columns = 0 To 4
tileType(rows, columns) = TYPE_KABOOM
Next
Next
MessageBox.Show(tileType(3, 3).Equals(TYPE_KABOOM))
I am trying to create a row of duplicated objects in PowerPoint, each with a motion path that is slightly shorter than the next, like this:
First Image
I know that you cannot add a path animation from scratch in VBA, so I used VBA to copy and paste an object and its motion path, then edit the motion path.
This is my VBA code:
Sub CopyPastePosition()
' Copy the shape in slide 2 which has a custom motion path aleady
ActivePresentation.Slides(2).Shapes(3).Copy
Dim x As Integer
' For loop - create 5 duplicates
For x = 1 To 5
' Each duplicate is nudged to the left by x*100
With ActivePresentation.Slides(1).Shapes.Paste
.Name = "Smiley"
.Left = x * 100
.Top = 1
End With
' This is where I am unsure - I want the motion path to be longer by x amount each time
ActivePresentation.Slides(1).TimeLine.MainSequence(x).Behaviors(1).MotionEffect.Path = "M 0 0 L 0 x*0.7"
Next x
End Sub
However, the output is like this:
Second Image
Path property for motion path which represents a VML string. The VML string is a collection of coordinates for a Line or Bezier curve (for
powerpoint purposes). The values are fractions of the slide dimensions.
You can generate an incrementing VML path with this function.
Function GetPath(MaxSegments As Integer, Increment As Single)
Dim path As String
Dim i As Integer
path = "M 0 0 "
For i = 1 To MaxSegments
path = path & "L 0 " & CStr(Increment * i) & " "
Next
path = path & " E"
GetPath = path
End Function
Since you are doing copy/paste of a shape with motion path already on it, I would also make this change to ensure we reference the correct motion path upon paste:
With ActivePresentation.Slides(1).TimeLine
.MainSequence(.MainSequence.Count).Behaviors(1).MotionEffect.path = GetPath(x, 0.7)
End With
Yes, I realise that I am trying to insert a variable into a string. yes the correct way of doing this is "M 0 0 L 0 " & (x * 0.7)
Thank you #braX
This is my third day programming in VBA for the first time. I have been taught C programming and Java programming in the past for reference. Making a custom Excel Macro from scratch. Struggling with this error. Have spent hours on it...
Purpose of application is to take data, and move it around between worksheets. This is only part of the code.
Error occurs in the IF-ELSE. Occurs in the else first, so the program has never tried to run the if portion yet.
Note that array1 is declared globally. It wont even let me set the first element to 5 for example. But if I try to change the value in the TempArray120 (which already has data stored) it works fine.
^thinking this is a declaration/instantiation issue
array1(i, 1) = ((TempArray120(i, 1) + TempArray277(i, 1)) / 2) 'getting the avg
^this is the line I am having trouble with
array1(1, 1) = 5
^this line also does not work
Dim array1() As Variant 'declare a array. The lower array determined by current
Dim array2() As Variant 'delcare a array. The upper array determined by current
Sub main()
Call DataFetch("Test", False)
Call DataFetch("Test1", True)
End Sub
Sub DataFetch(sheet As String, LowOrUpper As Boolean)
'Instance Variable Declaration
Dim TempArray120() As Variant 'create and array that will hold 10 values and the current for the 120volts
Dim TempArray277() As Variant 'create and array that will hold 10 values and the current for the 277 volts
TempArray120 = Worksheets(sheet).Range("F12:F2").Value 'read in the InPower from Dim lvl of 0Volts to 10volts #120volts
TempArray120(11, 1) = Worksheets(sheet).Range("K2").Value 'read in the OutCurrent at the 10Volt Dim lvl #120volts
TempArray277 = Worksheets(sheet).Range("F23:F13").Value 'read in the InPower from Dim lvl of 0Volts to 10volts #277volts
TempArray277(11, 1) = Worksheets(sheet).Range("K13").Value 'read in the OutCurrent at the 10Volt Dim lvl #277volts
'i belive the .value is correct for array use
'-------------------------------------------------------------------------------------------------------
'need to average this data and return to a global array. Needs to be the right array. Will check for that.
'LowOrUpper is flase for lower current and true for higher current
If LowOrUpper Then '-if the higher current data
For i = 1 To 11 Step 1
Set array2(i, 1) = ((TempArray120(i, 1).Value + TempArray277(i, 1).Value) / 2) 'set avg value to the global array. Note that this is for the lower array
Next 'end of for loop
Else '-was false and must be the lower current data
For i = 1 To 11 Step 1
array1(i, 1) = ((TempArray120(i, 1) + TempArray277(i, 1)) / 2) 'set avg value to the global array. Note that this is for the lower array
'array1(i, 1) = TempArray120(i, 1)
'this does not work. same error
'array1(1, 1) = 5
'this does not work. same error
'TempArray120(1,1)=5
'^this
Next 'end of for loop
End If
'-------------------------------------------------------------------------------------------------------
Call DataHandler
End Sub
'**********************************
Sub DataHandler()
'Instance Variable Declaration
'-------------------------------------------------------------------------------------------------------
'-------------------------------------------------------------------------------------------------------
'paste data into lower and upper curve. The data will the be generated. This is the First generation
Worksheets("Step 1 - Coarse Curve").Range("C7:C18").Value = array1 'setting the data values for Lower Curve.Data is in Array1. This should work 5/18/2017 spent a lot of time on this line
Worksheets("Step 1 - Coarse Curve").Range("K7:K17").Value = array2 'setting the data values for Upper Curve.Data is in Array2
Worksheets("Step 1 - Coarse Curve").Range("B5").Value = array1(11, 1).Value 'setting the current cell for lower
Worksheets("Step 1 - Coarse Curve").Range("J5").Value = array2(11, 1).Value 'setting the current cell for upper
Worksheets("Step 1 - Coarse Curve").Range("F5").Value = Worksheets("Main").Range("B5") 'sets the generated data current to user spec
'-------------------------------------------------------------------------------------------------------
'-------------------------------------------------------------------------------------------------------
'handle the data that was just generated => Transfer to the Fine curve
Worksheets("Step 2 - Fine Curve").Range("E3:E13").Value = Worksheets("Step 1 - Coarse Curve").Range("H7:H17").Value 'this is correct
Worksheets("Step 2 - Fine Curve").Range("A102").Value = ID 'insert the ID at the end of data!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!MUST EDIT
Dim fineData As Range 'this will be sent to the CSV file
Set fineData = Worksheets("Step 2 - Fine Curve").Range("B2:B102").Value 'do not believe this needs a .value??????
'-------------------------------------------------------------------------------------------------------
'-------------------------------------------------------------------------------------------------------
'Open new file. Make it visiable.
Dim myFile As String 'will hold path name
myFile = Application.DefaultFilePath & "\" & ID & ".csv" 'determine the pathname for new CSV file
Open myFile For Output As #1 'allows the file to be written to. Can now be refered to as #1 as well
'^if the file already exist it will be deleted and a new file will be created with same name
'now write in the array data
Write #1, fineData.Value
Close #1 'gotta close the file
'note the csv file is saved to the root directory of project
'-------------------------------------------------------------------------------------------------------
End Sub
You're off-by-one.
Implicitly sized arrays are 0-based*, unless specified otherwise by Option Base 1.
Given your example saying:
array1(1, 1) = 5 'doesn't work either
The only explanation is that you're assuming your arrays are 1-based, when they're 0-based.
*An array obtained from a Range will be 1-based.
Since you have a mix of 0-based implicitly-sized arrays and 1-based Range arrays in the same module, consider specifying Option Base 1 to unify the array bounds and work with 1-based arrays everywhere in the module, or you'll need to offset (-1/+1) array to cell coordinates.
before I start I want to point out that I tagged this question as VBA because I can't actually make a new tag for Winwrap and I've been told that Winwrap is pretty much the same as VBA.
I'm working on SPSS V19.0 and I'm trying to make a code that will help me identify and assign value labels to all values that don't have a label in the specified variable (or all variables).
The pseudo code below is for the version where it's a single variable (perhaps inputted by a text box or maybe sent via a custom dialogue in the SPSS Stats program (call the .sbs file from the syntax giving it the variable name).
Here is the Pseudo Code:
Sub Main(variable As String)
On Error GoTo bye
'Variable Declaration:
Dim i As Integer, intCount As Integer
Dim strValName As String, strVar As String, strCom As String
Dim varLabels As Variant 'This should be an array of all the value labels in the selected record
Dim objSpssApp As 'No idea what to put here, but I want to select the spss main window.
'Original Idea was to use two loops
'The first loop would fill an array with the value lables and use the index as the value and
'The second loop would check to see which values already had labels and then
'Would ask the user for a value label to apply to each value that didn't.
'loop 1
'For i = 0 To -1
'current = GetObject(variable.valuelist(i)) 'would use this to get the value
'Set varLabels(i) = current
'Next
'Loop for each number in the Value list.
strValName = InputBox("Please specify the variable.")
'Loop for each number in the Value list.
For i = 0 To varLabels-1
If IsEmpty (varLabels(i)) Then
'Find value and ask for the current value label
strVar = InputBox("Please insert Label for value "; varLabels(i);" :","Insert Value Label")
'Apply the response to the required number
strCom = "ADD VALUE LABELS " & strVar & Chr$(39) & intCount & Chr$(39) & Chr$(39) & strValName & Chr$(39) &" ."
'Then the piece of code to execute the Syntax
objSpssApp.ExecuteCommands(strCom, False)
End If
'intCount = intCount + 1 'increase the count so that it shows the correct number
'it's out of the loop so that even filled value labels are counted
'Perhaps this method would be better?
Next
Bye:
End Sub
This is in no way functioning code, it's just basically pseudo code for the process that I want to achieve I'm just looking for some help on it, if you could that would be magic.
Many thanks in advance
Mav
Winwrap and VBA are almost identical with differences that you can find in this post:
http://www.winwrap.com/web/basic/reference/?p=doc_tn0143_technote.htm
I haven't used winwrap, but I'll try to answer with my knowledge from VBA.
Dim varLabels As Variant
You can make an array out of this by saying for example
dim varLabels() as variant 'Dynamically declared array
dim varLabels(10) as variant 'Statically declared array
dim varLabels(1 to 10) as variant 'Array starting from 1 - which I mostly use
dim varLabels(1 to 10, 1 to 3) 'Multidimensional array
Dim objSpssApp As ?
"In theory", you can leave this as a variant type or even do
Dim objSpssApp
Without further declaration, which is basically the same - and it will work because a variant can be anything and will not generate an error. It is good custom though to declare you objects according to an explicit datatype in because the variant type is expensive in terms of memory. You should actually find out about the objects class name, but I cannot give you this. I guess that you should do something like:
set objSpssApp = new <Spss Window>
set objSpssApp = nothing 'In the end to release the object
Code:
'loop 1
For i = 0 To -1
current = GetObject(variable.valuelist(i)) 'would use this to get the value
Set varLabels(i) = current
Next
I don't exactly know why you want to count from 0 to -1 but perhaps it is irrelevant.
To fill an array, you can just do: varLabels(i) = i
The SET statement is used to set objects and you don't need to create an object to create an array. Also note that you did not declare half of the variables used here.
Code:
strVar = InputBox("Please insert Label for value "; varLabels(i);" :","Insert Value Label")
Note that the concatenation operator syntax is &.
This appears to be the same in WinWrap:
http://www.winwrap.com/web/basic/language/?p=doc_operators_oper.htm
But you know this, since you use it in your code.
Code:
'intCount = intCount + 1 'increase the count so that it shows the correct number
'it's out of the loop so that even filled value labels are counted
'Perhaps this method would be better?
I'm not sure if I understand this question, but in theory all loops are valid in any situation, it depends on your preference. For ... Next, Do ... Loop, While ... Wend, in the end they all do basically the same thing. intCount = intCount + 1 seems valid when using it in a loop.
Using Next (for ... next)
When using a counter, always use Next iCounter because it increments the counter.
I hope this reply may be of some use to you!