we have an .swf flash animation embedded into a visual basic application.
I am trying to read the contents of a text field in the animation called 'bob' using the following code;
TextBox1.Text = AxShockwaveFlash1.GetVariable("bob")
When executed the output in textbox1 is "_level0.bob" ???
This is different to the actual text in the animation, and idea how I can access it?
Have tried bob.text etc.
Thanks
Phil
Right found a solution that works with as3 and VB cobbled from a few other solutions, you need to use external interface in action script here is the code in AS3 and VB. Sends two strings hours and mins across.
AS3
function TimeUpdate(o:Object)
{
var r:String = "";
for (var v in o)
//Move the values from visual basic to mins and hours
if (v = "mins") mins = o[v];
if (v = "hours") hours = o[v];
time.text = hours + ":" + mins;
return "TimeUpdate was called";
}
if (ExternalInterface.available)
ExternalInterface.addCallback('TimeUpdate', TimeUpdate);
Visual Basic
Dim x As String
x = "<invoke name=""TimeUpdate"" returntype=""xml"">"
x = x & "<arguments>"
x = x & "<object>"
x = x & "<property id='hours'><string>2</string></property>"
x = x & "<property id='mins'><string>33</string></property>"
x = x & "</object>"
x = x & "</arguments>"
x = x & "</invoke>"
Dim responce As String
responce = AxShockwaveFlash1.CallFunction(x)
MsgBox(responce )
hope this is of use to people.
Phil
I think the problem you have is twofold. First, you need to be able to know somehow that the swf is ready. I tried to get this to work in a VBA app once (Access), and I never could reliably get this to work.
The second thing you need to realize is that the TextField is of type TextField, not String.
Related
I know this is how it's supposed to be done however, in VB.NET it gives me an overflow exception crashing my program. If there is any "VB.NET equivalent" of doing this, help is much appreciated.
Dim hActiveWeapon = _mem.rdInt(GetLocalBase() + &H2EE8)
Dim wepEntity = _mem.rdInt(_client + Offsets.EntityList + ((hActiveWeapon & &HFFF) - 1) * &H10) ' Crashes here # hActiveWeapon & &HFFF
Dim wepIndex = _mem.rdInt(wepEntity + Offsets.iItemDefinitionIndex)
I am doing this to get the lower 12 bytes of m_hActiveWeapon (0xFFF = 0b111111111111 = 4095), so I can get the index of the active weapon.
Meh the answer was simple, changing "&" to "And" fixed it.
I am writing a slot machine game for my intro to programming class. I can make the game procure 5 random images from a file containing 6, arrange them on a blank canvas and compare the pictures to see if there are 3-in-a-row. It will tell you if you win or not and ask you to play again. I need to loop the game so that it runs again after the user selects "y/n". here is my code so far.
from random import *
def main():
pictureList = setMediaPath("F:\Class Stuff\INF 120\Project X\gamepics")
s = 1 # requestInteger("Slot machine image numbering begins at:")
e = 6 # requestInteger("Slot maching image numbering ends at:")
ext = "jpg" #requestString("Enter the extension ofthe slot machine image files (without a dot):")
mypic = []
for num in range(s, e+1):
mypic = mypic + [(makePicture("smImage" + str(num) + "." + ext))]
#set up the "game board" in a blank window
w = getWidth(mypic[0])
h = getHeight(mypic[0])
ePic = makeEmptyPicture(w*5, h)
show(ePic)
# start the actual game
win = False
inRow = 1
last = -1
#loop through all five slots and set pic for each one a new, random picture. Form list of pictures.
#make a loop to run through the game until win = true.
for i in range(0,5):
imgIndex = randrange(0,len(mypic))
copyInto(mypic[imgIndex], ePic, i*w, 0)
repaint(ePic)
if imgIndex == last:
inRow = inRow + 1
else:
inRow = 1
last = imgIndex
if inRow >= 3:
win = true
if win == true:
showInformation("YOU WIN!!")
rePlay = requestString("Would you like to play again? (y/n)")
else:
showInformation("You Lose...")
requestString("Play again? (y/n)")
the media path is set to the directory on my machine with the images. here is a link to my google drive with the images. https://drive.google.com/folderview?id=0B_ZDD1CZGQYlYjFQWEpjR0NzMGs&usp=sharing .If you are going to run this, you need to change the media path in my code to correspond with where you have the pictures.
I appreciate any and all help with this. Thanks!
I dont know any jython but the pseudo code should be
var continue = true
while(continue) {
[[play game, set continue based on user input]]
}
So, I'm trying to create a function or two that takes html tags and colors them differently than the rest of the text (similar to how Visual Studio does it for key words like Dim). The only way I have found, is to use a rich text box and then do *.SelectionColor = Color.Blue, or something similar. Is there any other way to do this? I made it so whenever the textbox updates, it reads through it at changes all html tags to a different color. This works fine with a really short html file, but when they get to be larger, it takes too long, and the selection moves the cursor around.
So, is there any other way to do this, even if I have to use something other than a rich text box? If not, does anyone see a way to improve this?
Here are the two functions that run when the textbox updates. Tag is blue, attributes are red, stuff in quotes is green.
'//////////////////////////////////////////////////////////////////////////
'// findTag()
'// -finds a tag
'//////////////////////////////////////////////////////////////////////////
Private Function findTag()
Dim tag As String = ""
Dim i As Integer = 0
Dim startTag As Integer
While (i < txtCurrentFile.TextLength - 1)
If txtCurrentFile.Text(i) = "<" Then
startTag = i
While txtCurrentFile.Text(i) <> ">"
tag += txtCurrentFile.Text(i)
i += 1
End While
tag += ">"
colorCode(startTag, tag)
tag = ""
End If
i += 1
End While
Return Nothing
End Function
'//////////////////////////////////////////////////////////////////////////
'// colorCode()
'// -colors different tags accordingly
'//////////////////////////////////////////////////////////////////////////
Private Function colorCode(ByVal startIndex As Integer,
ByVal tag As String)
Dim i As Integer = 0
Dim isAttributes As Boolean = False
Do While (tag(i) <> " " And tag(i) <> ">")
txtCurrentFile.Select(startIndex + i, 1)
txtCurrentFile.SelectionColor = Color.Blue
i += 1
Loop
If i < tag.Length Then
Do Until (tag(i) = ">")
Do Until (tag(i) = Chr(34))
txtCurrentFile.Select(startIndex + i, 1)
txtCurrentFile.SelectionColor = Color.Red
i += 1
Loop
i += 1
Do Until (tag(i) = Chr(34))
txtCurrentFile.Select(startIndex + i, 1)
txtCurrentFile.SelectionColor = Color.Purple
i += 1
Loop
i += 1
Loop
txtCurrentFile.Select(startIndex + i, 1)
txtCurrentFile.SelectionColor = Color.Blue
End If
Return Nothing
End Function
a few suggestions:
Ditch the character scanner. Replace it with anything that is speedier (RegEx, HTML Agility Pack, ...)
If you really want to keep the character scanner, then limit the scan to the area around the modifications (say, 200 characters behind and in front of the cursor)
Remember where the cursor is before you start the color process and restore it when finished.
Implement a background colorizer that does a full file re-color on a separate thread (you'll have to clone the RTB and only apply the changes if the user hasn't made any changes while the colorizer was running).
... I don't know if this would work AT ALL!!!, but it could be cool if it did...
Maybe open the file in a webbrowser control and set your coloring rules in a css sheet??
Again, I don't know if this is a good idea or not, but it might do the trick very nicely since it's already HTML you're dealing with...
I am trying to speed up various aspects of my website.
The site is a shopping site various search pages which are slow. There are several potential reasons for this, one being working with images.
The other night I created a function which generates a thumbnail for my Facebook OG tags. The function writes a square image to the server 400px x 400px created by tiling the first few (up to 14) product images generated by a search query.
Running this script in total isolation on a test.aspx file gives me reasonable load time, but nothing I can do can speed it up, even when I don't return anything in the browser, just doing this process is taking about 3 seconds, which obviously expanded across the whole live site slows things down.
The entire code is:
Function mergeImgs(idList, imgList, head, fileName) As String
Try
Dim maxRows = HttpContext.Current.Request.QueryString("r")
Dim imgDim = 400
Dim Image3 As New Bitmap(imgDim, imgDim)
Dim g As Graphics = Graphics.FromImage(Image3)
Dim i = 0
Dim left = 0
Dim rows = 0
For Each item In idList
Dim img = Common.getImageUrl(idList(i), imgList(i), "server", "-tb")
i += 1
If img <> "/Images/awaiting.png" Then
Dim imageData As System.Drawing.Image = System.Drawing.Image.FromFile(img)
Dim aspect As Double = imageData.Width / imageData.Height ' determine aspect and decide how to display image
Dim Image1
Dim fixedHeight = imgDim / maxRows
Dim objGraphic As System.Drawing.Image = System.Drawing.Image.FromFile(img)
Dim aspectRatio = objGraphic.Height / objGraphic.Width
Dim reduction = fixedHeight / objGraphic.Height
Dim newwidth = objGraphic.Width * reduction
Image1 = New Bitmap(objGraphic, objGraphic.Width * reduction, fixedHeight)
g.DrawImage(Image1, New Point(left, fixedHeight * rows))
If left >= imgDim Then
rows += 1
left = 0
ElseIf left < imgDim Then
left += newwidth
ElseIf left < imgDim AndAlso rows = maxRows Then
Exit For
End If
End If
Next
Image3.Save(HttpContext.Current.Server.MapPath("/" & fileName), System.Drawing.Imaging.ImageFormat.Jpeg)
Return rootUrl & fileName
g.Dispose()
g = Nothing
Catch ex As Exception
Return ("<P>" & ex.ToString)
End Try
End Function
There's an external function getImageUrl which is simply a series of logic which writes out a directory structure based on the item ID, this is fast so I doubt holding it up at all.
Variables passed into the function are:
idList = a generic List(of String) ' a list of item IDs
imgList = a generic List(of String) ' a list of image names (image names only stored in DB)
head = the Page.Header ' not actually needed in this prototype, but aimed to allow this to write the OG tag to the Page Header
fileName = simply the name to give the generated image file
I can't help thinking that the section from
Dim imageData As System.Drawing.Image = System.Drawing.Image.FromFile(img)
onwards could potentially be sped up. What this does is work out the aspect ratio of the images loaded, then recalculate the size so they're all the same height so that the tile can be neatly populated in tidy rows.
Dim img = Common.getImageUrl(idList(i), imgList(i), "server", "-tb")
This line loads a thumbnail version ("-tb" in last variable) of the images concerned, so all images being dealt with are approx 50x50px so very small to load and determine the aspect ratios from
There are 4 versions of each image stored on my server, in 4 different sizes for fast display on the website, having messed around with the different images loaded here, it seems to make little difference to the script load time.
Is there anything faster than System.Drawing.Image.FromFile(img) that I can use to load in the images and determine the width and height of it?
There are a couple of other situations on my website where I am required to determine the dimensions of an image and then do something with it and all seem a bit slow.
Any advice most welcome!
Just for info, here's an example of an image generated by the above code
http://www.hgtrs.com/recents.jpg
This is generated from the products returned by this page (which might load slowly!):
http://www.hgtrs.com/search.aspx?Type=recents
I should state the my test.aspx file also includes a call to a database, having tested the query used directly, I get a query time of 0.18 seconds, I dont know how this time expands into a real application. I have optimised this query and the tables (it uses one nested query and a join) as much as I know how.
I've been trying to make a form with 68 items while positioning all the items on a form via a loop, but this loop isn't working :( Can someone please help me get this to work? I've tried looking everywhere but can't see what to do :/
Dim Items(67) As String
For x = 0 To 67
Items(x) = "Ctl" & x
Next
#It goes from 1 here as I manually set up 1 otherwise (x - 1) wont work.
For x = 1 To 67
Form_Home.Items(x).Top = 0
Form_Home.Items(x).Left = (Form_MainScreen.Items(x - 1).Left) + (Form_MainScreen.Items(x - 1).Width)
Form_Home.Items(x).Height = 225
Form_Home.Items(x).Width = 500
Next
Thank you everyone :)
What do you mean with Form_Home.Items? if you already have controls added to your forms, probably there is a Controls collection, so you can iterate trough it and set its properties, assuming each control has a name of the form Ctl0, Ctl1, Ctl2... then you can proceed as follow:
Dim ct_name as String
Dim ct_name_before as String
For x = 1 To 67
ct_name_before = "Ctl" & CStr(Cint(x-1))
ct_name = "Ctl" & CStr(x)
Form_Home.Controls(ct_name).Top = 0
Form_Home.Controls(ct_name).Left = (Form_MainScreen.Items(ct_name_before).Left) + _
(Form_MainScreen.Items(ct_name_before).Width)
Form_Home.Controls(ct_name).Height = 225
Next
Some version of VBA allow you to create array of controls sharing all the same name and having different index, then you can iterate through the array to get each control.