Moderated by: MystikShadows
Welcome Message and About this Forum  Visual Basic / VB.Net Resources & Tutorials   C# Resources & Links

PEEK and POKE in VB

by (Login burger2227)
R

'\\ API declarations...

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Long, Source As Long, ByVal Length As Long)

Private Declare Sub CopyMemoryByte Lib "kernel32" Alias "RtlMoveMemory" (Destination As Byte, Source As Long, ByVal Length As Long)

Private Declare Sub CopyMemoryFromByte Lib "kernel32" Alias "RtlMoveMemory" (Destination As Long, Source As Byte, ByVal Length As Long)


'These are then used in standard functions thus:


Public Function Peek(Address As Long) As Long

Call CopyMemory(Peek, ByVal Address, Len(Address))

End Function


Public Function PeekByte(Address As Long) As Byte

Call CopyMemoryByte(PeekByte, ByVal Address, Len(PeekByte))

End Function


Public Function Poke(Address As Long, Value As Long)

CopyMemory ByVal Address, Value, LenB(Value)

End Function


Public Function PokeByte(Address As Long, Value As Byte)

CopyMemoryFromByte ByVal Address, Value, LenB(Value)

End Function


'Example of use....

Dim lTest As Long

lTest = 100

Debug.Print lTest

Poke VarPtr(lTest), 300

Debug.Print lTest



'Ted



    
This message has been edited by burger2227 on Dec 6, 2009 3:41 PM
This message has been edited by burger2227 on Dec 6, 2009 3:22 PM
This message has been edited by burger2227 on Dec 5, 2009 3:58 PM

Posted on Dec 5, 2009, 1:58 PM

Respond to this message   

Return to Index


Resources

by Anonymous (no login)

If I have lots of resources and I dont want to put them all in the main .exe file what can I do?

Posted on May 1, 2009, 3:53 AM

Respond to this message   

Return to Index


Resource files

by Solitaire (Login Solitaire1)
S

Data is saved in a Resource file which becomes part of your project. If you choose Project resource file, it will place the file inside your project folder, making it portable. If you select Local resource, it will not become part of the project. But if you move your project folder elsewhere, it will not be able to find the selected file, so you need to use extra code to locate the file on the current computer.

Sorry I can't give you more details, but I only have limited experience working with Project resource image files. Not sure how or even if you can change from Project to Local after the original choice was made. I hope I gave you enough information so you can try to work it out for yourself.

Posted on May 1, 2009, 12:14 PM

Respond to this message   

Return to Index


How?

by Anonymous (no login)

I use VB2008 where can I change that?

Posted on May 6, 2009, 10:41 AM

Respond to this message   

Return to Index


* Sorry we don't answer anonymous people. Get a name!

by (Login burger2227)
R

Posted on May 6, 2009, 11:55 AM

Respond to this message   

Return to Index


*Yes we do, that's why we don't require registration.

by (Login PhyloGenesis)
R

*

Posted on May 25, 2009, 12:41 PM

Respond to this message   

Return to Index


* Qbasic code CAN be used in VB! Ask here.......

by (Login burger2227)
R



    
This message has been edited by burger2227 on Jun 29, 2009 1:38 PM
This message has been edited by burger2227 on May 25, 2009 2:44 PM

Posted on May 25, 2009, 2:32 PM

Respond to this message   

Return to Index


SWF Component

by JPCS5917 (no login)

Hi
I saw a topic in a forum about hacking flash games using VB6.I have VB2008 but I need a SWF Component that I cant find in 2008.Im using windows vista so my VB6 install program doesnt work.What can I do now?

Posted on Apr 2, 2009, 8:14 AM

Respond to this message   

Return to Index


What exactly are you trying to do?

by (Login burger2227)
R

Did you try searching Google? I found a SWF to bitmap program for .NET here:

http://swf-to-image.bytescout.qarchive.org/

I searched "VB swf components"

Ted

PS: If you EVER want to use VB6 again downgrade to XP. VISTA sucks!



    
This message has been edited by burger2227 on Apr 2, 2009 2:43 PM

Posted on Apr 2, 2009, 2:40 PM

Respond to this message   

Return to Index


Have you tried...

by (Login MystikShadows)
VB-Forum

To right click on the setup icon and making sure you select "run as administrator" ?

Posted on Apr 14, 2009, 5:13 PM

Respond to this message   

Return to Index


* I think he should have bookmarked the Forum. :P

by (Login burger2227)
R

Posted on Apr 14, 2009, 9:50 PM

Respond to this message   

Return to Index


* that sounds like a good idea yes. ;).

by (Login MystikShadows)
VB-Forum

Posted on Apr 15, 2009, 3:04 AM

Respond to this message   

Return to Index


* Solitaire and I should be able to answer most questions.

by (Login burger2227)
R



    
This message has been edited by burger2227 on Mar 15, 2009 2:19 PM

Posted on Mar 15, 2009, 12:28 PM

Respond to this message   

Return to Index


* Mystik is on a moving sabbatical. Hope they have Internet there!

by (Login burger2227)
R



    
This message has been edited by burger2227 on Feb 26, 2009 12:31 PM

Posted on Feb 26, 2009, 12:31 PM

Respond to this message   

Return to Index


Why?

by Iain (Login Iain_Mcphee)
R

It seems that if you follow M$'s programming conventions for VB.NET, you end up with code that I can't read and uses far too much memory.

Posted on Jan 2, 2009, 7:39 PM

Respond to this message   

Return to Index


Because M$ thinks they can just redo anything they want.

by (Login burger2227)
R

The hell with backward compatability too! Full speed ahead! "M$ needs more money for Bill's pension."

Ted



    
This message has been edited by burger2227 on Jan 4, 2009 12:36 PM

Posted on Jan 3, 2009, 1:42 PM

Respond to this message   

Return to Index


Merry Christmas Myst and good luck with moving...

by (Login The-Universe)
Admin

For those who may have wonder why MystikShadows has not been around much this month, he and his family are in the middle of a move. From what I've seen of the weather near where he and his family live, that is no easy task this time of year. Best wishes Myst to you and yours and I hope you will be back with us soon for the New Year.

Pete

Posted on Dec 25, 2008, 10:29 AM

Respond to this message   

Return to Index


Console Calculator with title instructions

by Solitaire (Login Solitaire1)
S

I just learned about the Console command that changes the title of the window in VB 2005 or VB 2008. I wrote a simple calculator program as a Console application and added the instructions in the title, rather than repeat it on the output screen. I also added more console features that lengthen the screen and give the user option to scroll when reaching the bottom or clearing the screen. Program is designed to permit only valid inputs for the operators. Incorrect number inputs will return 0. Other features were added and improved as I edited the code later this evening.

Start a new Console application and copy/paste this code. It should automatically indent each line properly inside the IDE, but you will need to add more spaces in the title string (in place of the underlines) to separate the instructions for Space and Esc:





Module Module1

Sub Main()
Dim oper As String, first, num As Double, over As Boolean
Dim start As Boolean = False
Dim result As Double = 0
Dim ent As String = ""
Dim sresult As String = ""
Dim repeat As Integer = 0
Dim lresult As Long = 0
Dim row As Integer = 0
Console.WindowHeight = 38
Console.Title = "Console Calculator ---- Operators + - * / \ ^ Mod ___ Space clears; ___ Back restarts; ___ Esc exits"
Do
repeat += 1
over = False
If result = 0 And start = False Then
Console.Write("Enter the first number: ")
ent = Console.ReadLine()
Double.TryParse(ent, result)
Console.WriteLine()
Else
Console.WriteLine("The starting number is " & result)
Console.WriteLine()
End If
Console.Write("Type operator, space, Backspace, or Esc: ")
Do
oper = Console.ReadKey(True).KeyChar
oper = oper.ToLower()
Loop While ("+-*/\^m " & Chr(27) & Chr(8)).IndexOf(oper, 0) = -1
If oper = "m" Then
Console.Write("Mod")
Else
Console.Write(oper)
End If
Console.WriteLine(vbCrLf)
If "+-*/\^m".IndexOf(oper, 0) > -1 Then
Console.Write("Enter the second number: ")
ent = Console.ReadLine()
End If
Double.TryParse(ent, num)
first = result
Select Case oper
Case "+"
result += num
Case "-"
result -= num
Case "*"
result *= num
Case "/"
If num = 0 Then num = 1
result /= num
Case "\"
lresult = Convert.ToInt64(result)
lresult \= Convert.ToInt64(num)
result = lresult
Case "^"
result ^= num
If result > 1.79769313486231E+308 Or result < -1.79769313486231E+308 Then
result = first
sresult = ("Result is beyond upper or lower limit")
over = True
End If
Case "m"
result = result Mod num
oper = "Mod"
Case " "
result = 0
Console.Clear()
start = False
repeat = 0
Case Chr(8)
row = Console.CursorTop
Console.CursorTop = row - 4
Console.CursorLeft = 0
Console.Write(StrDup(160, " "))
Console.CursorTop = row - 4
result = 0
start = False
Case Chr(27)
Exit Do
Case Else
oper = " "
Console.Clear()
End Select
If over = False Then sresult = result.ToString
If oper <> " " And oper <> Chr(8) Then
Console.WriteLine()
Console.WriteLine(vbTab & first & " " & oper & " " & num & " = " & sresult)
Console.WriteLine()
Console.Write(StrDup(80, "="))
End If
If oper <> " " And oper <> Chr(8) Then start = True
If repeat Mod 4 = 0 And Console.CursorTop >= 34 Then
Console.WriteLine("Enter to clear screen, Tab to scroll to top, any other key to continue down...")
ent = Console.ReadKey(True).KeyChar
If ent = Chr(13) Then
Console.Clear()
repeat = 0
ElseIf ent = Chr(9) Then
Console.CursorTop = Console.CursorTop - 1
Console.WriteLine(StrDup(80, " "))
Console.CursorTop = Console.CursorTop - 2
Console.WindowTop = repeat * 9
Else
row = Console.CursorTop
Console.CursorTop = row - 1
Console.CursorLeft = 0
Console.Write(StrDup(80, " "))
Console.CursorTop = row - 1
End If
End If
Loop Until oper = Chr(27)
Console.WriteLine(vbCrLf)
Console.WriteLine("Press any key to Exit Console Calculator")
Console.ReadKey(True)
End Sub

End Module



    
This message has been edited by Solitaire1 on Nov 22, 2008 5:53 PM
This message has been edited by Solitaire1 on Nov 22, 2008 12:42 AM
This message has been edited by Solitaire1 on Nov 22, 2008 12:40 AM
This message has been edited by Solitaire1 on Nov 21, 2008 10:48 PM
This message has been edited by Solitaire1 on Nov 21, 2008 10:47 PM
This message has been edited by Solitaire1 on Nov 21, 2008 10:39 PM
This message has been edited by Solitaire1 on Nov 21, 2008 1:05 PM
This message has been edited by Solitaire1 on Nov 21, 2008 1:01 PM
This message has been edited by Solitaire1 on Nov 21, 2008 12:13 PM
This message has been edited by Solitaire1 on Nov 21, 2008 11:02 AM
This message has been edited by Solitaire1 on Nov 21, 2008 11:01 AM
This message has been edited by Solitaire1 on Nov 21, 2008 10:59 AM
This message has been edited by Solitaire1 on Nov 21, 2008 10:52 AM

Posted on Nov 21, 2008, 10:50 AM

Respond to this message   

Return to Index


* Pete, this Forum says "Login" and I cannot edit stuff.

by (Login burger2227)
R

Posted on Nov 6, 2008, 12:32 AM

Respond to this message   

Return to Index


* Thanks, it should work now.

by Pete (Login The-Universe)
Admin

Posted on Nov 6, 2008, 1:12 AM

Respond to this message   

Return to Index


Counting characters in a string

by Solitaire (Login Solitaire1)
S

This seems to be a simple problem at first but turns out to be more challenging than expected.

Each character in the string is to be output in order of appearance, without duplication, with the number of repeats listed next to it.

For example, if the string is "accbedbc" the output should be:
a -- 1
c -- 3
b -- 2
e -- 1
d -- 1

Furthermore, it should be done using nested For Each loops, and will probably need to use Char() arrays for comparison.

Any ideas? I posted a similar QB problem in the main forum:

http://www.network54.com/Forum/13959/message/1222886914/Count+characters+in+string

Posted on Oct 2, 2008, 8:58 PM

Respond to this message   

Return to Index


How about a Keypress event and an Array?

by (Login burger2227)
R

You can toss the keypress counts directly into the array as the user types it. In QB I would use one INKEY$ loop and filter out invalid characters like spaces and "." for example.

Ted

Posted on Oct 2, 2008, 9:32 PM

Respond to this message   

Return to Index


Here is an Array routine using MID$, ASC and two FOR loops

by (Login burger2227)
R

DEFINT A-Z

DIM Chrs(65 TO 90)
CLS
Check$ = "abbc cdefhdf"
L = LEN(Check$): Check$ = UCASE$(Check$)
PRINT Check$

FOR i = 1 TO L
    letter$ = MID$(Check$, i, 1)
    code = ASC(letter$)
    IF code > 64 AND code < 91 THEN  'array bounds
       IF Chrs(code) = 0 THEN   'don't repeat a letter
        FOR j = i TO L
          IF ASC(MID$(Check$, j, 1)) = code THEN Chrs(code) = Chrs(code) + 1
        NEXT
        PRINT letter$; "---"; Chrs(code)  'print by string order
       END IF
    END IF
NEXT

SYSTEM

You could also just print the array in alphabetical order when an index > 0 after it is done looping.

Ted



    
This message has been edited by burger2227 on Oct 3, 2008 8:54 AM
This message has been edited by burger2227 on Oct 3, 2008 8:30 AM
This message has been edited by burger2227 on Oct 3, 2008 8:24 AM

Posted on Oct 3, 2008, 8:18 AM

Respond to this message   

Return to Index


Thank you, Clippy, but your code belongs in the main forum, not here.

by Solitaire (Login Solitaire1)
S

It works nicely in QB, but this is for VB.NET.

I did specify VB.NET code using >>For Each<< loops and >>Char<< arrays (not available in QB). In addition, I didn't mention it, but legacy code (such as INSTR, MID, etc.) are to be avoided. I'm sure it can be worked out with some effort.

FYI:
The Substring() method replaces MID. The IndexOf() method replaces INSTR. Both methods are zero-based. The syntax differs from the old legacy functions. Examples:
initial = myname.Substring(0, 1).ToUpper()
returnvar = mainstring.IndexOf(instring, startpos)

The For Each loop construct works with arrays and collections. This is always zero-based. However, For Each always includes the complete array range from 0 to the upperbound value, so individual indexes or ranges cannot be singled out.

The Chars() property returns a single character in a string and is zero-based. It takes one number argument -- the location in a string, starting with 0 for the first position.

A string can be assigned to a Char array using the stringname.ToCharArray method.

Example of extracting letters from an alphanumeric string:

Dim newstr As String = ""
Dim alfanum As String = TextBox1.Text
Dim n As Integer = alfanum.Length
Dim carry(n - 1) As Char
carry = alfanum.ToCharArray
For Each ch As Char in carry
   If Char.IsLetter(ch) Then newstr &= ch
Next
TextBox2.Text = newstr

Posted on Oct 3, 2008, 4:21 PM

Respond to this message   

Return to Index


I knew that! I figured INSTR would create problems too.

by (Login burger2227)
R

IF that is supposed to be the latest in VB.NET programming technology THEN count me out! M$ always has to mess with simplicity and that accounts for all of their Bloated software ......................... plus the excess money we must pay. Not only do they change stuff, but they don't even care about backward compatability anymore!

Don't even expect me to play with their new OOPS system of programming, please. I use VB6, but M$ is gonna kill that soon too.

Ted

 



    
This message has been edited by burger2227 on Oct 3, 2008 5:20 PM

Posted on Oct 3, 2008, 5:06 PM

Respond to this message   

Return to Index


Easy

by qbguy (no login)

SHELL "qbasic /run count.bas"

Posted on Oct 4, 2008, 5:31 AM

Respond to this message   

Return to Index


Or in Vista

by qbguy (no login)

Shell "c:/qb64/compile.exe count.bas"
Shell "c:/qb64/count.exe"

Posted on Oct 4, 2008, 5:41 AM

Respond to this message   

Return to Index


*How true QBguy.............

by (Login burger2227)
R

Posted on Oct 4, 2008, 2:23 PM

Respond to this message   

Return to Index