Guest User

Untitled

a guest
Sep 27th, 2011
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 78.12 KB | None | 0 0
  1. vb.net cheats :
  2.  
  3. walkthrough in the description
  4.  
  5. name of game : feZet v1
  6. created by : moti barski
  7.  
  8. [IMG]http://img163.imageshack.us/img163/8595/unledjho.png[/IMG]
  9.  
  10. http://imageshack.us/photo/my-images/163/unledjho.png/
  11.  
  12. name of game : feZet v1
  13. compiler (programming platform) : vb.net express edition 2010
  14. created by : moti barski ( which also made the yotamarker A.I)
  15.  
  16. this is a 2 player programmable 2 player versus game
  17.  
  18. 13 character vs game, each char has dif magic.
  19. wins counter
  20.  
  21.  
  22. after 2 battles p2 do an action or move if game jams up
  23.  
  24. controls :
  25. p1 :
  26. a <-, s->, t hit, g grab, y shield, u charge magic, j magic
  27.  
  28. p2 :
  29. left arrow <-, right arrow ->, insert hit, Delete grab,Home shield, Page Up charge magic, Page Down magic
  30. up to select character
  31.  
  32. install walkthrough :
  33. in c:\ make a fezet named folder
  34. add files : 1.bmp - 13.bmp (characters images
  35. add files : magicp1.bmp, magicp2.bmp ' magic displayed arena for char 1 or 2
  36.  
  37. if only using the .exe file of the game .net 3.5 framework or above should be installed
  38.  
  39.  
  40. Public Class Form1 ' this is the feZet : a 2 player versus game written by Moti Barski
  41. ' programmacaly addables to this game :
  42. ' joystick, fatality,digivolution,sounds, story mode, game genres, online play
  43. ' codes enabling the above features can be found in the free to download book battle programming
  44. ' form control list : picturebox 1,2 size : 106,146
  45. Dim magic1, magic2 As Bitmap ' images displayed after magic in respect of character
  46. Dim char1Selected As Boolean = False
  47. Dim ar(0 To 12) As Bitmap ' character array
  48. Dim char1, char2, p1ATK, p2ATK, p1Magicfill, p2magicfill As Integer
  49. Dim p1X As Integer = 1 ' position of char 1
  50. Dim p1JumpForeward As Integer = 10 'can be calibrated
  51. Dim p1JumpBackward As Integer = 5
  52. Dim p2X As Integer = p1X + 900
  53. Dim p2JumpForeward As Integer = 10
  54. Dim p2JumpBackward As Integer = 5
  55. Dim direction As Char = "N" ' N = no direction taken not left not right m'k
  56. Dim direction2 As Char = "N"
  57. Dim Action As Byte = 0 ' 0 nothing,1-hit,2-grab,3-magic fill,4magic, 5 shield
  58. Dim Action2 As Byte = 0
  59. Dim charSpace As Integer = 50 ' minimum space betwin the 2 chars when close
  60. Dim p1Wins As Integer = 0
  61. Dim p2Wins As Integer = 0
  62. Dim boolchar1 As Boolean = True ' if true char 1 will work magic
  63. Function charsWereSelected(ByVal pNum As Byte) As String
  64. 'set character name after selection
  65. Dim charName As String = ""
  66. Select Case pNum
  67. Case 1
  68. charName = "moti barski"
  69. Case 2
  70. charName = "Lord_Rat"
  71. Case 3
  72. charName = "kregg"
  73. Case 4
  74. charName = "FunkyDexter"
  75. Case 5
  76. charName = "baja yu"
  77. Case 6
  78. charName = "Milk"
  79. Case 7
  80. charName = "Pc_Not_Mac"
  81. Case 8
  82. charName = "namrekka"
  83. Case 9
  84. charName = "Shaggy Hiker"
  85. Case 10
  86. charName = "stlaural"
  87. Case 11
  88. charName = "zaza"
  89. Case 12
  90. charName = "nissan cohen"
  91. Case 13
  92. charName = "Jenner"
  93. Case Else
  94.  
  95. End Select
  96. Return charName
  97. End Function
  98.  
  99. Sub gotHit(ByVal player As Byte) ' player 1 or 2 goes to it's respective side and hp is reduced unless he has sp magic
  100. If player = 2 Then
  101. p2X = 901
  102. PictureBox2.Location = New Point(p2X, PictureBox2.Location.Y)
  103. ' lower p2 hp by p1 ATK
  104. Dim Temp1 As Byte
  105. Temp1 = ProgressBar4.Value
  106. If Temp1 - p1ATK >= 0 Then
  107. ProgressBar4.Value -= p1ATK
  108. Else
  109. ProgressBar4.Value = 0
  110. End If
  111. Else
  112. p1X = 1
  113. PictureBox1.Location = New Point(p1X, PictureBox1.Location.Y)
  114. ' lower p1 hp by p2 ATK
  115. Dim Temp1 As Byte
  116. Temp1 = ProgressBar3.Value
  117. If Temp1 - p2ATK >= 0 Then
  118. ProgressBar3.Value -= p2ATK
  119. Else
  120. ProgressBar3.Value = 0
  121. End If
  122. End If
  123. End Sub
  124. Sub magic(ByVal player As Integer)
  125. Dim char3 As Integer = 0 ' anti glitch for char 3
  126. Dim regionalBool As Boolean = False ' anti glitch for char 2
  127. If player = 1 Then
  128. If ProgressBar1.Value = ProgressBar1.Maximum Then
  129. Select Case char1
  130. Case 1 ' teleport hadoken
  131. If boolchar1 Then
  132. If Action2 <> 5 Then
  133. If ProgressBar4.Value - 50 < 0 Then
  134. ProgressBar4.Value = 0
  135. Else
  136. ProgressBar4.Value -= 50
  137. End If
  138. Else ' if not needed
  139. If ProgressBar3.Value - 10 < 0 Then
  140. ProgressBar3.Value = 0
  141. Else
  142. ProgressBar3.Value -= 10
  143. End If
  144. End If
  145. End If
  146. boolchar1 = Not boolchar1
  147. Case 2 ' eat magic
  148. ProgressBar1.Value = 90
  149. ProgressBar2.Value = 0
  150. regionalBool = True
  151. Case 3 'replace char
  152. Dim tb As Bitmap
  153. tb = PictureBox1.Image
  154. PictureBox1.Image = PictureBox2.Image
  155. PictureBox2.Image = tb
  156. Dim tHp As Integer
  157. tHp = ProgressBar3.Value
  158. ProgressBar3.Value = ProgressBar4.Value
  159. ProgressBar4.Value = tHp
  160. ' replace magicbar maximum
  161. tHp = ProgressBar1.Maximum
  162. ProgressBar1.Maximum = ProgressBar2.Maximum
  163. ProgressBar2.Maximum = tHp
  164. char3 = ProgressBar2.Value
  165. ProgressBar2.Value = 0
  166. tHp = p1ATK ' replace ATK
  167. p1ATK = p2ATK
  168. p2ATK = tHp
  169. tHp = p1JumpForeward 'replace speed
  170. p1JumpForeward = p2JumpForeward
  171. p2JumpForeward = tHp
  172. tHp = char1 ' replace char
  173. char1 = char2
  174. char2 = tHp
  175. Case 4
  176. If ProgressBar3.Value < 31 Then
  177. ProgressBar4.Value = 30
  178. End If
  179. Case 5 ' hard to defeat near end of battle
  180. ProgressBar3.Value = 15
  181. Case 6 ' heal (milk drink)
  182. Dim tx As Integer
  183. tx = ProgressBar3.Value
  184. If tx + 5 > 100 Then
  185. tx = 100
  186. End If
  187. ProgressBar3.Value = tx + 5
  188. Case 7
  189. If ProgressBar4.Value - 10 < 0 Then
  190. ProgressBar4.Value = 0
  191. Else
  192. ProgressBar4.Value -= 10
  193. End If
  194. Case 8 'death note
  195. ProgressBar4.Value = 0
  196. Case 9 ' reversable invisibility (lurk)
  197. PictureBox1.Visible = Not PictureBox1.Visible
  198. Case 10 ' death rollet
  199. If Second(Now) Mod 2 = 1 Then
  200. ProgressBar3.Value = 0
  201. Else
  202. ProgressBar4.Value = 0
  203. End If
  204. Case 11
  205. If ProgressBar4.Value > 90 Then
  206. ProgressBar3.Value = 100
  207. End If
  208. Case 12
  209. p1ATK += 1
  210. Case 13
  211. ProgressBar3.Value = 1
  212. ProgressBar4.Value = 1
  213. End Select
  214. Me.BackgroundImage = magic1
  215. If Not regionalBool Then
  216. ProgressBar1.Value = char3 ' or 0 (char3 is special case)
  217. End If
  218. End If
  219.  
  220. Else ' player 2
  221. If ProgressBar2.Value = ProgressBar2.Maximum Then
  222. Select Case char2
  223. Case 1
  224. If boolchar1 Then
  225. If Action2 <> 5 Then
  226. If ProgressBar3.Value - 50 < 0 Then
  227. ProgressBar3.Value = 0
  228. Else
  229. ProgressBar3.Value -= 50
  230. End If
  231. Else
  232. If ProgressBar4.Value - 10 < 0 Then
  233. ProgressBar4.Value = 0
  234. Else
  235. ProgressBar4.Value -= 10
  236. End If
  237. End If
  238. End If
  239. boolchar1 = Not boolchar1
  240. Case 2 ' eat magic
  241. ProgressBar1.Value = 90
  242. ProgressBar2.Value = 0
  243. regionalBool = True
  244. Case 3 'replace char
  245. Dim tb As Bitmap
  246. tb = PictureBox1.Image
  247. PictureBox1.Image = PictureBox2.Image
  248. PictureBox2.Image = tb
  249. Dim tHp As Integer
  250. tHp = ProgressBar3.Value
  251. ProgressBar3.Value = ProgressBar4.Value
  252. ProgressBar4.Value = tHp
  253. ' replace magicbar maximum
  254. tHp = ProgressBar1.Maximum
  255. ProgressBar1.Maximum = ProgressBar2.Maximum
  256. ProgressBar2.Maximum = tHp
  257. char3 = ProgressBar1.Value
  258. ProgressBar1.Value = 0
  259. tHp = p1ATK ' replace ATK
  260. p1ATK = p2ATK
  261. p2ATK = tHp
  262. tHp = p1JumpForeward 'replace speed
  263. p1JumpForeward = p2JumpForeward
  264. p2JumpForeward = tHp
  265. tHp = char1 ' replace char
  266. char1 = char2
  267. char2 = tHp
  268. Case 4
  269. If ProgressBar4.Value < 31 Then
  270. ProgressBar3.Value = 30
  271. End If
  272. Case 5
  273. ProgressBar4.Value = 15
  274. Case 6
  275. Dim tx As Integer
  276. tx = ProgressBar4.Value
  277. If tx + 5 > 100 Then
  278. tx = 100
  279. End If
  280. ProgressBar4.Value = tx + 5
  281. Case 7
  282. If ProgressBar3.Value - 10 < 0 Then
  283. ProgressBar3.Value = 0
  284. Else
  285. ProgressBar3.Value -= 10
  286. End If
  287. Case 8 'death note
  288. ProgressBar3.Value = 0
  289. Case 9 ' reversable
  290. PictureBox2.Visible = Not PictureBox2.Visible
  291. Case 10
  292. If Second(Now) Mod 2 = 1 Then
  293. ProgressBar3.Value = 0
  294. Else
  295. ProgressBar4.Value = 0
  296. End If
  297. Case 11
  298. If ProgressBar3.Value > 90 Then
  299. ProgressBar4.Value = 100
  300. End If
  301. Case 12
  302. p2ATK += 1
  303. Case 13
  304. ProgressBar3.Value = 1
  305. ProgressBar4.Value = 1
  306. End Select
  307. Me.BackgroundImage = magic2
  308. If Not regionalBool Then
  309. ProgressBar2.Value = char3 ' or 0 char3 is special case
  310. End If
  311. End If
  312. End If
  313. End Sub
  314. Sub isBattleOver() ' if so variables are reset
  315. If ProgressBar3.Value = 0 Then
  316. Label5.Visible = True
  317. Timer1.Enabled = False
  318. PictureBox2.Location = New Point(901, PictureBox2.Location.Y)
  319. PictureBox1.Location = New Point(1, PictureBox1.Location.Y)
  320. boolchar1 = True
  321. PictureBox1.Visible = True
  322. PictureBox2.Visible = True
  323. TextBox1.Text = "1"
  324. p1JumpForeward = 10
  325. p2JumpForeward = 10
  326. p1ATK = 5
  327. p2ATK = 5
  328. Me.BackgroundImage = Nothing
  329. If ProgressBar4.Value = 0 Then
  330. Label5.Text = "draw"
  331. p1Wins += 1
  332. p2Wins += 1
  333. Label3.Text = p1Wins & " " & "WINS"
  334. Label4.Text = p2Wins & " " & "WINS"
  335. ElseIf ProgressBar4.Value = 100 Then
  336. Label5.Text = "player 2 wins flawless victory"
  337. p2Wins += 1
  338. Label4.Text = p2Wins & " " & "WINS"
  339. Else
  340. Label5.Text = "player 2 wins"
  341. p2Wins += 1
  342. Label4.Text = p2Wins & " " & "WINS"
  343. End If
  344. ElseIf ProgressBar4.Value = 0 Then
  345. Label5.Visible = True
  346. Timer1.Enabled = False
  347. PictureBox2.Location = New Point(901, PictureBox2.Location.Y)
  348. PictureBox1.Location = New Point(1, PictureBox1.Location.Y)
  349. TextBox1.Text = "1"
  350. boolchar1 = True
  351. p1JumpForeward = 10
  352. p2JumpForeward = 10
  353. Me.BackgroundImage = Nothing
  354. If ProgressBar3.Value = 0 Then
  355. Label5.Text = "draw"
  356. p1Wins += 1
  357. p2Wins += 1
  358. Label3.Text = p1Wins & " " & "WINS"
  359. Label4.Text = p2Wins & " " & "WINS"
  360. ElseIf ProgressBar3.Value = 100 Then
  361. Label5.Text = "player 1 wins flawless victory"
  362. p1Wins += 1
  363. Label3.Text = p1Wins & " " & "WINS"
  364. Else
  365. Label5.Text = "player 1 WINS"
  366. p1Wins += 1
  367. Label3.Text = p1Wins & " " & "WINS"
  368. End If
  369. End If
  370. End Sub
  371. Private Sub TextBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
  372. ' get input
  373. Try
  374. If Not Timer1.Enabled And Not char1Selected Then
  375. If e.KeyCode = Keys.Right Then
  376. If Not TextBox1.Text = 1 Then
  377. TextBox1.Text -= 1
  378. PictureBox1.Image = ar(TextBox1.Text - 1)
  379. Label1.Text = charsWereSelected(TextBox1.Text)
  380. End If
  381. ElseIf e.KeyCode = Keys.Left And Not TextBox1.Text > 12 Then
  382. TextBox1.Text += 1
  383. PictureBox1.Image = ar(TextBox1.Text - 1)
  384. Label1.Text = charsWereSelected(TextBox1.Text)
  385. ElseIf e.KeyCode = Keys.Up Then
  386. char1Selected = True
  387. char1 = TextBox1.Text
  388. 'special char
  389. If char1 = 12 Then
  390. p1JumpForeward = 15
  391. ElseIf char1 = 8 Then
  392. ProgressBar1.Maximum = 300
  393. End If
  394. 'end of special char
  395. TextBox1.Text = 1
  396. p1ATK = 5
  397. End If
  398. ElseIf Not Timer1.Enabled And char1Selected Then
  399. If e.KeyCode = Keys.Right Then
  400. If Not TextBox1.Text = 1 Then
  401. TextBox1.Text -= 1
  402. PictureBox2.Image = ar(TextBox1.Text - 1)
  403. Label2.Text = charsWereSelected(TextBox1.Text)
  404. End If
  405. ElseIf e.KeyCode = Keys.Left And Not TextBox1.Text > 12 Then
  406. TextBox1.Text += 1
  407. PictureBox2.Image = ar(TextBox1.Text - 1)
  408. Label2.Text = charsWereSelected(TextBox1.Text)
  409. ElseIf e.KeyCode = Keys.Up And char1 <> TextBox1.Text Then
  410. char1Selected = False
  411. char2 = TextBox1.Text
  412. 'special at char select char
  413. If char2 = 12 Then
  414. p2JumpForeward = 15
  415. ElseIf char2 = 8 Then
  416. ProgressBar2.Maximum = 300
  417. End If
  418. 'end of special char
  419. TextBox1.Text = ""
  420. Action = 0
  421. Action2 = 0
  422. direction = "N"
  423. direction2 = "N"
  424. p2ATK = 5
  425. Label5.Visible = False
  426. ProgressBar3.Value = 100
  427. ProgressBar4.Value = 100
  428. ProgressBar2.Value = 0
  429. ProgressBar1.Value = 0
  430. Timer1.Enabled = True
  431. End If
  432. End If
  433. Catch ex As Exception
  434. TextBox1.Text = "1"
  435. End Try
  436.  
  437. ' player1
  438. If e.KeyCode = Keys.S Then
  439. direction = "R"
  440. ElseIf e.KeyCode = Keys.A Then
  441. direction = "L"
  442. ElseIf e.KeyCode = Keys.T Then
  443. Action = 1
  444. ElseIf e.KeyCode = Keys.G Then
  445. Action = 2
  446. ElseIf e.KeyCode = Keys.U Then
  447. Action = 3
  448. ElseIf e.KeyCode = Keys.J Then
  449. Action = 4
  450. ElseIf e.KeyCode = Keys.Y Then
  451. Action = 5
  452. End If
  453. 'player2
  454. If e.KeyCode = Keys.Right Then
  455. direction2 = "R"
  456. ElseIf e.KeyCode = Keys.Left Then
  457. direction2 = "L"
  458. ElseIf e.KeyCode = Keys.Insert Then
  459. Action2 = 1
  460. ElseIf e.KeyCode = Keys.Delete Then
  461. Action2 = 2
  462. ElseIf e.KeyCode = Keys.PageUp Then
  463. Action2 = 3
  464. ElseIf e.KeyCode = Keys.PageDown Then
  465. Action2 = 4
  466. ElseIf e.KeyCode = Keys.Home Then
  467. Action2 = 5 ' * defend
  468. End If
  469. End Sub
  470. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  471. ' initialize variables at form load event
  472. Dim fs1 As IO.FileStream = New IO.FileStream("c:\fezet\" & "magicp1.bmp", IO.FileMode.Open)
  473. magic1 = Image.FromStream(fs1)
  474. Dim fs2 As IO.FileStream = New IO.FileStream("c:\fezet\" & "magicp2.bmp", IO.FileMode.Open)
  475. magic2 = Image.FromStream(fs2)
  476. Label5.Visible = False
  477. Label3.Text = "0 win"
  478. Label4.Text = "0 win"
  479. Label1.Text = "moti barski"
  480. Label2.Text = "moti barski"
  481. ProgressBar3.Value = 100
  482. ProgressBar4.Value = 100
  483. TextBox1.Text = 1
  484. For index = 1 To 13
  485. Dim fs As IO.FileStream = New IO.FileStream("c:\fezet\" & TextBox1.Text & ".bmp", IO.FileMode.Open)
  486. ar(index - 1) = Image.FromStream(fs)
  487. fs.Close()
  488. TextBox1.Text += 1
  489. Next
  490. TextBox1.Text = 1
  491. Me.Width = 1000
  492. PictureBox2.Location = New Point(1000 - PictureBox2.Width, PictureBox2.Location.Y)
  493. PictureBox1.Location = New Point(1, PictureBox1.Location.Y)
  494. End Sub
  495.  
  496. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  497. ' the battle is here
  498. Dim areClose As Boolean = False 'combo how to
  499. Dim areCloseEnougth As Boolean = False
  500. If direction = "R" Then
  501. If p1X + p1JumpForeward + charSpace < p2X Then 'p1jump + space of chars as var
  502. p1X += p1JumpForeward
  503. PictureBox1.Location = New Point(p1X, PictureBox1.Location.Y)
  504. Else
  505. areClose = True
  506. End If
  507. ElseIf direction = "L" Then
  508. If p1X - p1JumpBackward > 1 Then
  509. p1X -= p1JumpBackward
  510. PictureBox1.Location = New Point(p1X, PictureBox1.Location.Y)
  511. End If
  512. End If
  513. If direction2 = "L" Then
  514. If p2X - p2JumpForeward - charSpace > p1X Then
  515. p2X -= p2JumpForeward
  516. PictureBox2.Location = New Point(p2X, PictureBox2.Location.Y)
  517. Else
  518. areClose = True
  519. End If
  520. ElseIf direction2 = "R" Then
  521. If p2X + p2JumpBackward < 900 Then
  522. p2X += p2JumpBackward
  523. PictureBox2.Location = New Point(p2X, PictureBox2.Location.Y)
  524. End If
  525. End If
  526. If p1X + p1JumpForeward + charSpace >= p2X Then
  527. areCloseEnougth = True
  528. End If
  529. '0 nothing,1-hit,2-grab,3-magic fill,4magic
  530. If areCloseEnougth Then ' use areclose boolean for move close + move
  531. If Action = 1 Then 'p1 hit
  532. If Action2 = 0 Or Action2 = 2 Or Action2 = 3 Or Action2 = 4 Then
  533. ' spin p1, lower p2 hp p2 pos to back
  534. Dim bm As Bitmap = PictureBox1.Image
  535. bm.RotateFlip(RotateFlipType.Rotate180FlipX)
  536. PictureBox1.Image = bm
  537. gotHit(2)
  538. ElseIf Action2 = 5 Then
  539. ' stop hit p1
  540. Action = 0
  541. ElseIf Action2 = 1 Then
  542. 'spin hit p1,p2 pos p1,p2 to back
  543. Dim bm As Bitmap = PictureBox1.Image
  544. bm.RotateFlip(RotateFlipType.Rotate180FlipX)
  545. PictureBox1.Image = bm
  546. bm = PictureBox2.Image
  547. bm.RotateFlip(RotateFlipType.Rotate180FlipX)
  548. PictureBox2.Image = bm
  549. gotHit(2)
  550. gotHit(1)
  551. End If
  552. ElseIf Action = 5 Then
  553. If Action2 = 1 Then
  554. Action2 = 0
  555. ElseIf Action2 = 2 Then
  556. ' pos p1 back,lower p1 hp, spin grab p2
  557. gotHit(1)
  558. Dim bm As Bitmap = PictureBox2.Image
  559. bm.RotateFlip(RotateFlipType.Rotate90FlipY)
  560. PictureBox2.Image = bm
  561. ElseIf Action2 = 3 Then
  562. 'p2 magic fill
  563. If ProgressBar2.Value < ProgressBar2.Maximum Then
  564. ProgressBar2.Value += 1
  565. End If
  566. ElseIf Action2 = 4 Then
  567. 'magic p2
  568. magic(2)
  569. End If
  570. ElseIf Action = 2 Then
  571. If Action2 = 1 Then
  572. 'p1 lower hp, p1 go to back, p2hit spin
  573. Dim bm As Bitmap = PictureBox2.Image
  574. bm.RotateFlip(RotateFlipType.Rotate180FlipX)
  575. PictureBox2.Image = bm
  576. gotHit(1)
  577. ElseIf Action2 = 0 Or Action2 = 3 Or Action2 = 4 Or Action2 = 5 Then
  578. 'p1 grab spin, p2 lower hp,p2 go back
  579. Dim bm As Bitmap = PictureBox1.Image
  580. bm.RotateFlip(RotateFlipType.Rotate90FlipY)
  581. PictureBox1.Image = bm
  582. gotHit(2)
  583. ElseIf Action2 = 2 Then
  584. 'p1 p2 lower hp and go back and grab spin
  585. Dim bm As Bitmap = PictureBox1.Image
  586. bm.RotateFlip(RotateFlipType.Rotate90FlipY)
  587. PictureBox1.Image = bm
  588. bm = PictureBox2.Image
  589. bm.RotateFlip(RotateFlipType.Rotate90FlipY)
  590. PictureBox2.Image = bm
  591. gotHit(1)
  592. gotHit(2)
  593. End If
  594. ElseIf Action = 0 Then
  595. If Action2 = 1 Then
  596. 'p2 hit spin ,p1 lower hp go back
  597. Dim bm As Bitmap = PictureBox2.Image
  598. bm.RotateFlip(RotateFlipType.Rotate180FlipX)
  599. PictureBox2.Image = bm
  600. gotHit(1)
  601. ElseIf Action2 = 2 Then
  602. 'p2 grab spin ,p1 lower hp go back
  603. Dim bm As Bitmap = PictureBox2.Image
  604. bm.RotateFlip(RotateFlipType.Rotate90FlipY)
  605. PictureBox2.Image = bm
  606. gotHit(1)
  607. ElseIf Action2 = 3 Then
  608. 'p2 magic fill
  609. If ProgressBar2.Value < ProgressBar2.Maximum Then
  610. ProgressBar2.Value += 1
  611. End If
  612. ElseIf Action2 = 4 Then
  613. 'p2 magic
  614. magic(2)
  615. End If
  616. ElseIf Action = 3 Then
  617. If Action2 = 4 Then
  618. 'p2 magic
  619. magic(2)
  620. ElseIf Action2 = 2 Then
  621. 'p2 grab spin,p1 lower hp go back
  622. Dim bm As Bitmap = PictureBox2.Image
  623. bm.RotateFlip(RotateFlipType.Rotate90FlipY)
  624. PictureBox2.Image = bm
  625. gotHit(1)
  626. ElseIf Action2 = 1 Then
  627. 'p2 hit spin, p1 lower hp, go back
  628. Dim bm As Bitmap = PictureBox2.Image
  629. bm.RotateFlip(RotateFlipType.Rotate180FlipX)
  630. PictureBox2.Image = bm
  631. gotHit(1)
  632. ElseIf Action2 = 5 Then
  633. 'magic fill p1
  634. If ProgressBar1.Value < ProgressBar1.Maximum Then
  635. ProgressBar1.Value += 1
  636. End If
  637. ElseIf Action2 = 0 Then
  638. 'magic fill p1
  639. If ProgressBar1.Value < ProgressBar1.Maximum Then
  640. ProgressBar1.Value += 1
  641. End If
  642. ElseIf Action2 = 3 Then
  643. 'p1,p2 magic fill
  644. magic(1)
  645. magic(2)
  646. If ProgressBar1.Value < ProgressBar1.Maximum Then
  647. ProgressBar1.Value += 1
  648. End If
  649. If ProgressBar2.Value < ProgressBar2.Maximum Then
  650. ProgressBar2.Value += 1
  651. End If
  652. End If
  653. ElseIf Action = 4 Then
  654. If Action2 = 3 Then
  655. 'p1 magic
  656. magic(1)
  657. ElseIf Action2 = 1 Then
  658. 'p1 go back lower health,p2 hit spin
  659. Dim bm As Bitmap = PictureBox2.Image
  660. bm.RotateFlip(RotateFlipType.Rotate180FlipX)
  661. PictureBox2.Image = bm
  662. gotHit(1)
  663. ElseIf Action2 = 0 Or Action2 = 5 Then
  664. 'p1 magic
  665. magic(1)
  666. ElseIf Action2 = 2 Then
  667. 'p2 grab spin, p1 lower hp go back
  668. Dim bm As Bitmap = PictureBox2.Image
  669. bm.RotateFlip(RotateFlipType.Rotate90FlipY)
  670. PictureBox2.Image = bm
  671. gotHit(1)
  672. End If
  673. End If
  674. ElseIf Action = 1 Then
  675. 'p1 hit spin
  676. Dim bm As Bitmap = PictureBox1.Image
  677. bm.RotateFlip(RotateFlipType.Rotate180FlipX)
  678. PictureBox1.Image = bm
  679. ElseIf Action = 2 Then
  680. 'p1 grab spin
  681. Dim bm As Bitmap = PictureBox1.Image
  682. bm.RotateFlip(RotateFlipType.Rotate90FlipY)
  683. PictureBox1.Image = bm
  684. ElseIf Action = 3 Then
  685. 'p1 magic fill
  686. If ProgressBar1.Value < ProgressBar1.Maximum Then
  687. ProgressBar1.Value += 1
  688. End If
  689. ElseIf Action = 4 Then
  690. 'p1 magic
  691. magic(1)
  692. End If
  693. If Not areClose Then
  694. If Action2 = 1 Then
  695. 'p2 hit spin
  696. Dim bm As Bitmap = PictureBox2.Image
  697. bm.RotateFlip(RotateFlipType.Rotate180FlipX)
  698. PictureBox2.Image = bm
  699. ElseIf Action2 = 2 Then
  700. 'p2 grab spin
  701. Dim bm As Bitmap = PictureBox2.Image
  702. bm.RotateFlip(RotateFlipType.Rotate90FlipY)
  703. PictureBox2.Image = bm
  704. ElseIf Action2 = 3 Then
  705. 'p2 magic fill
  706. If ProgressBar2.Value < ProgressBar2.Maximum Then
  707. ProgressBar2.Value += 1
  708. End If
  709. ElseIf Action2 = 4 Then
  710. 'p2 magic
  711. magic(2)
  712. End If
  713. End If
  714. TextBox1.Text = "" '* from hya
  715. 'is battle over count p1 p2 :win, draw (both) or flawless victory or p1,2 win stop timer reset textbox to 1, image1
  716. isBattleOver()
  717. End Sub
  718.  
  719. Private Sub TextBox1_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
  720. ' enable p1 and p2 simoltanious input
  721. If e.KeyCode = Keys.S Or e.KeyCode = Keys.A Then
  722. direction = "N"
  723. ElseIf e.KeyCode = Keys.T Or e.KeyCode = Keys.G Or e.KeyCode = Keys.U Or e.KeyCode = Keys.J Or e.KeyCode = Keys.Y Then
  724. Action = 0
  725. End If
  726. If e.KeyCode = Keys.Right Or e.KeyCode = Keys.Left Then
  727. direction2 = "N"
  728. ElseIf e.KeyCode = Keys.Insert Or e.KeyCode = Keys.Delete Or e.KeyCode = Keys.Home Or e.KeyCode = Keys.PageUp Or e.KeyCode = Keys.PageDown Then
  729. Action2 = 0
  730. End If
  731. End Sub 'exit btn
  732. End Class
  733.  
  734.  
  735. TCP CHAT
  736.  
  737.  
  738. client :
  739.  
  740. '5 textboxes txtIP, txtPort, txtUsername, txtMain, txtSend
  741. 'btnconnect,btnsend,btndisconnect
  742. Public Class frmMainClient
  743. Private client As System.Net.Sockets.TcpClient
  744. Private Const BYTES_TO_READ As Integer = 255
  745. Private readBuffer(BYTES_TO_READ) As Byte
  746. Private Delegate Sub WriteText(ByVal text As String)
  747. Private Sub BtnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnConnect.Click
  748. If txtIP.Text = "" Or txtPort.Text = "" Or txtUserName.Text = "" Or IsNumeric(txtPort.Text) = False Or txtUserName.Text.IndexOf("|") >= 0 Then MsgBox("Fill text boxes properly") : Exit Sub
  749. client = New System.Net.Sockets.TcpClient(txtIP.Text, txtPort.Text)
  750. client.GetStream.BeginRead(readBuffer, 0, BYTES_TO_READ, AddressOf DoRead, Nothing)
  751. SendMessage("/CONNECT|" & txtUserName.Text)
  752. txtUserName.Enabled = False
  753. BtnSend.Enabled = True
  754. BtnConnect.Enabled = False
  755. txtSend.Enabled = True
  756. txtIP.Enabled = False
  757. txtPort.Enabled = False
  758. End Sub
  759. Private Sub DoRead(ByVal ar As System.IAsyncResult)
  760. Dim totalRead As Integer
  761. Try
  762. totalRead = client.GetStream.EndRead(ar) 'Ends the reading and returns the number of bytes read.
  763. Catch ex As Exception
  764. 'The underlying socket have probably been closed OR an error has occured whilst trying to access it, either way, this is where you should remove close all eventuall connections 'to this client and remove it from the list of connected clients.
  765. End Try
  766. If totalRead > 0 Then
  767. 'the readBuffer array will contain everything read from the client
  768. Dim receivedString As String = System.Text.Encoding.UTF8.GetString(readBuffer, 0, totalRead)
  769. MessageReceived(receivedString)
  770. End If
  771. Try
  772. client.GetStream.BeginRead(readBuffer, 0, BYTES_TO_READ, AddressOf DoRead, Nothing) 'Begin the reading again.
  773. Catch ex As Exception
  774. 'The underlying socket have probably been closed OR an error has occured whilst trying to access it, either way, this is where you should remove close all eventuall connections 'to this client and remove it from the list of connected clients.
  775. End Try
  776. End Sub
  777. Private Sub MessageReceived(ByVal message As String)
  778. Select Case message
  779. Case "/Connected"
  780. ConnectionStatus("Client : Connected")
  781. Case Else
  782. WriteToMainText(message & vbCrLf)
  783. End Select
  784.  
  785. End Sub
  786. Private Sub ConnectionStatus(ByVal Message As String)
  787. If Me.InvokeRequired Then
  788. Me.Invoke(New WriteText(AddressOf ConnectionStatus), Message)
  789. Else
  790. Me.Text = "Client : Connected"
  791. BtnDisconnect.Visible = True
  792. BtnConnect.Height = 36
  793. BtnConnect.Top = 9
  794. End If
  795. End Sub
  796. Private Sub WriteToMainText(ByVal Message As String)
  797. If txtMain.InvokeRequired Then
  798. Me.Invoke(New WriteText(AddressOf WriteToMainText), Message)
  799. Else
  800. txtMain.AppendText(Message)
  801. txtMain.SelectionStart = txtMain.Text.Length
  802. End If
  803. End Sub
  804. Private Sub SendMessage(ByVal Msg As String)
  805. Dim sw As IO.StreamWriter
  806. Try
  807. sw = New IO.StreamWriter(client.GetStream)
  808. sw.Write(Msg)
  809. sw.Flush()
  810. Catch ex As Exception
  811. MessageBox.Show(ex.ToString)
  812. End Try
  813. End Sub
  814.  
  815. Private Sub frmMainClient_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  816. BtnDisconnect.Visible = False
  817. txtMain.ReadOnly = True
  818. BtnSend.Enabled = False
  819. txtSend.Enabled = False
  820. End Sub
  821.  
  822. Private Sub BtnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSend.Click
  823. SendMessage(txtUserName.Text & ": " & txtSend.Text)
  824. WriteToMainText(txtUserName.Text & ": " & txtSend.Text & vbCrLf)
  825. txtSend.Text = ""
  826. End Sub
  827.  
  828. Private Sub BtnDisconnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnDisconnect.Click
  829. SendMessage("/DISCONNECT|" & txtUserName.Text)
  830. BtnConnect.Enabled = True
  831. BtnDisconnect.Visible = False
  832. txtUserName.Enabled = True
  833. BtnSend.Enabled = False
  834. txtSend.Enabled = False
  835. txtIP.Enabled = True
  836. txtPort.Enabled = True
  837. Me.Text = "Client"
  838. End Sub
  839.  
  840. Private Sub txtSend_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtSend.Enter
  841. Me.AcceptButton = BtnSend
  842. End Sub
  843. End Class
  844.  
  845. server :
  846.  
  847. 'We have
  848. '4 textboxes txtSend, txtUsername, txtPort, txtMain (txtMain is multiline and readonly)
  849. 'lblConnection
  850. 'btnListen, btnSend, btnSendAll
  851. 'listbox lbClients
  852. Public Class frmMainServer
  853. Private listener As System.Net.Sockets.TcpListener
  854. Private listenThread As System.Threading.Thread
  855. Private clients As New List(Of ConnectedClient) 'This list will store all connected clients.
  856. Private Delegate Sub StringDelegate(ByVal text As String)
  857.  
  858. Private Sub frmMainServer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  859. 'lblRemoveClient.Visible = False
  860. txtMain.ReadOnly = True
  861. txtSend.Enabled = False
  862. BtnSend.Enabled = False
  863. btnSendAll.Enabled = False
  864. End Sub
  865. Private Sub DoListen()
  866. Dim incomingClient As System.Net.Sockets.TcpClient
  867. Do
  868. incomingClient = listener.AcceptTcpClient 'Accept the incoming connection. This is a blocking method so execution will halt here until someone tries to connect.
  869. ' Dim connClient As New ConnectedClient(incomingClient) 'Create a new instance of ConnectedClient (check its constructor to see whats happening now).
  870. Dim connClient As New ConnectedClient(incomingClient, Me) 'Create a new instance of ConnectedClient (check its constructor to see whats happening now).
  871. AddHandler connClient.dataReceived, AddressOf Me.MessageReceived
  872. ' clients.Add(New ConnectedClient(incomingClient)) 'Adds the connected client to the list of connected clients.
  873. clients.Add(connClient) 'Adds the connected client to the list of connected clients.
  874. ' AddHandler connClient.dataReceived, AddressOf Me.MessageReceived
  875. Loop
  876. End Sub
  877.  
  878. Public Sub removeClient(ByVal client As ConnectedClient)
  879. If clients.Contains(client) Then
  880. clients.Remove(client)
  881. For x = 0 To lbClients.Items.Count - 1
  882. If lbClients.Items.Item(x) = client.Username Then RemoveClientFromListBox(x) : Exit For
  883. Next
  884. End If
  885. End Sub
  886. Private Sub RemoveClientFromListBox(ByVal IndexOfClient As String)
  887. If lbClients.InvokeRequired Then
  888. Me.Invoke(New StringDelegate(AddressOf RemoveClientFromListBox), IndexOfClient)
  889. Else
  890. lbClients.Items.Remove(lbClients.Items.Item(Val(IndexOfClient)))
  891. End If
  892. End Sub
  893. Private Sub BtnListen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnListen.Click
  894. If txtPort.Text = "" Or txtUserName.Text = "" Or IsNumeric(txtPort.Text) = False Or txtUserName.Text.IndexOf("|") >= 0 Then MsgBox("Fill text boxes properly") : Exit Sub
  895. listener = New System.Net.Sockets.TcpListener(System.Net.IPAddress.Any, txtPort.Text) 'The TcpListener will listen for incoming connections at port 43001
  896. listener.Start() 'Start listening.
  897. listenThread = New System.Threading.Thread(AddressOf DoListen) 'This thread will run the doListen method
  898. listenThread.IsBackground = True 'Since we dont want this thread to keep on running after the application closes, we set isBackground to true.
  899. listenThread.Start() 'Start executing doListen on the worker thread.
  900. txtPort.Enabled = False
  901. BtnListen.Enabled = False
  902. txtUserName.Enabled = False
  903. End Sub
  904. Private Sub MessageReceived(ByVal sender As ConnectedClient, ByVal Message As String) 'A message has been received from one of the clients. 'To determine who its from, use the sender object. 'sender.SendMessage can be used to reply to the sender.
  905. ' If Mid(Message, 1, 1) = "/" Then
  906. ' Select Case Mid(Message, 2, 8)
  907. ' Case "Connect:"
  908. ' sender.SendMessage("/Connected")
  909. ' SetConnectionLabelText("Connected")
  910. ' Case Else
  911. ' WriteToMainText(Message)
  912. ' End Select
  913. ' End If
  914. Dim data() As String = Message.Split("|"c)
  915. Select Case data(0)
  916. Case "/CONNECT"
  917. If GetClientByName(data(1)) Is Nothing Then
  918. sender.Username = data(1)
  919. AddClientToListBox(data(1))
  920. End If
  921. SetConnectionLabelText("Connected")
  922. sender.SendMessage("/Connected")
  923. Case "/DISCONNECT"
  924. removeClient(sender)
  925. Case Else
  926. WriteToMainText(Message & vbCrLf)
  927. End Select
  928. End Sub
  929. Private Function GetClientByName(ByVal name As String) As ConnectedClient
  930. For Each cc As ConnectedClient In clients
  931. If cc.Username = name Then
  932. Return cc 'client found, return it
  933. End If
  934. Next
  935. Return Nothing
  936. End Function
  937.  
  938. Private Sub AddClientToListBox(ByVal ClientName As String)
  939. If lbClients.InvokeRequired Then
  940. Me.Invoke(New StringDelegate(AddressOf AddClientToListBox), ClientName)
  941. Else
  942. lbClients.Items.Add(ClientName)
  943. If (lbClients.SelectedIndex < 0) And (lbClients.Items.Count > 0) Then lbClients.SelectedIndex = 0
  944. End If
  945. End Sub
  946.  
  947. Private Sub WriteToMainText(ByVal Message As String)
  948. If txtMain.InvokeRequired Then
  949. Me.Invoke(New StringDelegate(AddressOf WriteToMainText), Message)
  950. Else
  951. ' Dim Usr As String
  952. ' Usr = Mid(Message, 1, Message.IndexOf("|"))
  953. txtMain.Text = txtMain.Text & Message
  954. txtMain.SelectionStart = txtMain.Text.Length
  955. End If
  956. End Sub
  957.  
  958. Private Sub SetConnectionLabelText(ByVal text As String)
  959. If Me.LblConnection.InvokeRequired Then
  960. Me.Invoke(New StringDelegate(AddressOf SetConnectionLabelText), text)
  961. Else
  962. Me.LblConnection.Text = text
  963. BtnListen.Enabled = False
  964. BtnSend.Enabled = True
  965. btnSendAll.Enabled = True
  966. txtSend.Enabled = True
  967. End If
  968. End Sub
  969.  
  970. Private Sub BtnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSend.Click
  971. If txtSend.Text <> "" And lbClients.SelectedIndex >= 0 Then
  972. Dim cc As ConnectedClient
  973. cc = GetClientByName(Convert.ToString(lbClients.SelectedItem))
  974. cc.SendMessage(txtUserName.Text & ": " & txtSend.Text)
  975. WriteToMainText(txtUserName.Text & ": " & txtSend.Text & vbCrLf)
  976. txtSend.Text = ""
  977. End If
  978. End Sub
  979.  
  980. Private Sub btnSendAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSendAll.Click
  981. If txtSend.Text <> "" Then
  982. For Each cc As ConnectedClient In clients
  983. cc.SendMessage(txtUserName.Text & ": " & txtSend.Text)
  984. WriteToMainText(txtUserName.Text & ": " & txtSend.Text & vbCrLf)
  985. Next
  986. txtSend.Text = ""
  987. End If
  988. End Sub
  989.  
  990. Private Sub txtSend_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtSend.Enter
  991. Me.AcceptButton = BtnSend
  992. End Sub
  993. End Class
  994.  
  995. Public Class ConnectedClient
  996. Private mClient As System.Net.Sockets.TcpClient
  997. Private Const BYTES_TO_READ As Integer = 255
  998. Private readBuffer(BYTES_TO_READ) As Byte
  999. Private mUsername As String
  1000. Private mParentForm As frmMainServer
  1001. Public Event dataReceived(ByVal sender As ConnectedClient, ByVal message As String)
  1002.  
  1003. Sub New(ByVal client As System.Net.Sockets.TcpClient, ByVal parentForm As frmMainServer)
  1004. mParentForm = parentForm
  1005. mClient = client
  1006. mClient.GetStream.BeginRead(readBuffer, 0, BYTES_TO_READ, AddressOf doRead, Nothing) 'This will start reading from the stream between this server and the connected client.
  1007. End Sub
  1008.  
  1009.  
  1010. Public Property Username() As String
  1011. Get
  1012. Return mUsername
  1013. End Get
  1014. Set(ByVal value As String)
  1015. mUsername = value
  1016. End Set
  1017. End Property
  1018. Private Sub doRead(ByVal ar As System.IAsyncResult)
  1019. Dim totalRead As Integer
  1020. Try
  1021. totalRead = mClient.GetStream.EndRead(ar) 'Ends the reading and returns the number of bytes read.
  1022. Catch ex As Exception
  1023. mParentForm.removeClient(Me)
  1024. Exit Sub
  1025. 'The underlying socket have probably been closed OR an error has occured whilst trying to access it, either way, this is where you should remove close all eventuall connections
  1026. 'to this client and remove it from the list of connected clients.
  1027. End Try
  1028.  
  1029. If totalRead > 0 Then
  1030. 'the readBuffer array will contain everything read from the client.
  1031. Dim receivedString As String = System.Text.Encoding.UTF8.GetString(readBuffer, 0, totalRead)
  1032. RaiseEvent dataReceived(Me, receivedString)
  1033. End If
  1034.  
  1035. Try
  1036. mClient.GetStream.BeginRead(readBuffer, 0, BYTES_TO_READ, AddressOf doRead, Nothing) 'Begin the reading again.
  1037. Catch ex As Exception
  1038. 'The underlying socket have probably been closed OR an error has occured whilst trying to access it, either way, this is where you should remove close all eventuall connections
  1039. 'to this client and remove it from the list of connected clients.
  1040. End Try
  1041. End Sub
  1042.  
  1043. Public Sub SendMessage(ByVal msg As String)
  1044. Dim sw As IO.StreamWriter
  1045. Try
  1046. sw = New IO.StreamWriter(mClient.GetStream) 'Create a new streamwriter that will be writing directly to the networkstream.
  1047. sw.Write(msg)
  1048. sw.Flush()
  1049. Catch ex As Exception
  1050. MessageBox.Show(ex.ToString)
  1051. End Try
  1052. 'As opposed to writing to a file, we DONT call close on the streamwriter, since we dont want to close the stream.
  1053. End Sub
  1054. End Class
  1055.  
  1056.  
  1057. SOUND MANIPULATION :
  1058.  
  1059.  
  1060. Option Strict Off
  1061. Option Explicit On
  1062. Friend Class MP3Class
  1063. '
  1064. Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer
  1065. Public Declare Function auxGetVolume Lib "winmm.dll" (ByVal uDeviceID As Long, ByVal lpdwVolume As Long) As Long
  1066. Public Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Integer) As Integer
  1067. Public MP3File As String
  1068. Dim TheFile As String
  1069. Dim movieBox As PictureBox
  1070. Public retVal As Integer ' used to store our return value from the mci interface
  1071. Private retData As String = Space$(128) ' used to store our return data from various commands
  1072. Private _volLevel As Integer = Nothing
  1073. Private _dMS As Integer = Nothing
  1074. Private _dSec As Integer = Nothing
  1075. Private _fDur As String = Nothing
  1076. Private _posMS As Integer = Nothing
  1077. Private _posSec As Integer = Nothing
  1078. Private _fPos As String = Nothing
  1079. Private _rChanValue As Boolean = False
  1080. Private _lChanValue As Boolean = False
  1081. Private _tRemainingMS As Integer = Nothing
  1082. Private _tRemainingSec As Integer = Nothing
  1083. Private _fTRemaining As String = Nothing
  1084. Private _muteOutput As Boolean = False
  1085.  
  1086. Public Function MP3Playing() As Boolean
  1087. On Error GoTo TheError
  1088. Static s As New Integer()
  1089. mciSendString("status " & TheFile & " mode", s.Equals(30), Len(s.Equals(30)), 0)
  1090. MP3Playing = (Mid(s.Equals(30), 1, 7) = "playing")
  1091. Exit Function
  1092. TheError: MsgBox(Err.Description, , " Error")
  1093. End Function
  1094. Public Function MP3SavePlayList(ByRef TheFile As String, ByRef playlist As ListBox) As Object
  1095. On Error GoTo TheError
  1096. Dim i As Short
  1097. Dim a As String
  1098. FileOpen(1, TheFile, OpenMode.Output)
  1099. For i = 0 To playlist.Items.Count - 1
  1100. a = playlist.Items(i)
  1101. PrintLine(1, a)
  1102. Next
  1103. FileClose(1)
  1104. Exit Function
  1105. TheError: MsgBox(Err.Description, , " Error")
  1106. End Function
  1107.  
  1108. Public Function MP3OpenPlayList(ByRef TheFile As String, ByRef playlist As ListBox) As Object
  1109. On Error GoTo TheError
  1110. Dim test As String
  1111. If TheFile = "" Then Exit Function
  1112. FileOpen(1, TheFile, OpenMode.Input)
  1113. While Not EOF(1)
  1114. test = LineInput(1)
  1115. playlist.Items.Add(RTrim(test))
  1116. End While
  1117. FileClose(1)
  1118. Exit Function
  1119. TheError: MsgBox(Err.Description, , " Error")
  1120. End Function
  1121. Public Function GetLastBackSlash(ByRef text As String) As String
  1122. On Error GoTo TheError
  1123. Dim i As Object
  1124. Dim pos As Short
  1125. Dim lastslash As Short
  1126.  
  1127.  
  1128. For i = 1 To Len(text)
  1129.  
  1130. pos = InStr(i, text, "\", CompareMethod.Text)
  1131. If pos <> 0 Then lastslash = pos
  1132. Next i
  1133. GetLastBackSlash = Right(text, Len(text) - lastslash)
  1134. Exit Function
  1135. TheError: MsgBox(Err.Description, , " Error")
  1136. End Function
  1137.  
  1138. 'Take the path and .mp3 off the file
  1139. Public Sub ListNoChar(ByRef playlist As System.Windows.Forms.ListBox, ByVal playlistPath As System.Windows.Forms.ListBox)
  1140. On Error GoTo TheError
  1141. Dim X As Object
  1142. Dim NoChar As String
  1143. Dim NoEnd As String
  1144.  
  1145. For X = 0 To playlistPath.Items.Count - 1
  1146.  
  1147. NoChar = GetLastBackSlash(playlistPath.Items(X))
  1148. NoEnd = RightLeft(NoChar, ".")
  1149. 'NoEnd = Mid(NoChar, 1, 1)
  1150. playlist.Items.Add(playlist.Items.Count + 1 & ". " & NoEnd)
  1151. Next X
  1152. Exit Sub
  1153. TheError: MsgBox(Err.Description, , " Error")
  1154. End Sub
  1155.  
  1156. Function GetFileExtension(ByVal strFileName As String) As String
  1157. Dim lngPosition As Long
  1158.  
  1159. lngPosition = InStrRev(strFileName, ".")
  1160. If lngPosition Then
  1161. GetFileExtension = Mid$(strFileName, lngPosition + 1)
  1162. End If
  1163. End Function
  1164.  
  1165. Public Function RightLeft(ByRef source As String, ByRef token As String) As String
  1166. On Error GoTo TheError
  1167. Dim i As Short
  1168. RightLeft = ""
  1169. '
  1170. For i = Len(source) To 1 Step -1
  1171. '
  1172. If Mid(source, i, 1) = token Then
  1173. RightLeft = Left(source, i - 1)
  1174. Exit Function
  1175. End If
  1176. Next i
  1177. Exit Function
  1178. TheError: MsgBox(Err.Description, , " Error")
  1179.  
  1180. End Function
  1181. Private Function NoEndChar(ByRef playlistPath As System.Windows.Forms.ListBox) As String
  1182. On Error GoTo TheError
  1183. Dim N As Object
  1184. For N = 0 To playlistPath.Items.Count - 1
  1185.  
  1186. Next N
  1187. Exit Function
  1188. TheError: MsgBox(Err.Description, , " Error")
  1189. End Function
  1190.  
  1191. Sub MP3Play()
  1192. mciSendString("close " & TheFile, CStr(0), 0, 0)
  1193. TheFile = Chr(34) & Trim(MP3File) & Chr(34)
  1194. mciSendString("open " & TheFile, CStr(0), 0, 0)
  1195. mciSendString("play " & TheFile, "", 0, 0)
  1196. Exit Sub
  1197. TheError: MsgBox(Err.Description, , " Error")
  1198.  
  1199. End Sub
  1200. Sub MP3Stop()
  1201. TheFile = Chr(34) & Trim(MP3File) & Chr(34)
  1202. mciSendString("close " & TheFile, CStr(0), 0, 0)
  1203. Exit Sub
  1204. TheError: MsgBox(Err.Description, , " Error")
  1205.  
  1206. End Sub
  1207. Sub MP3Resume()
  1208. TheFile = Chr(34) & Trim(MP3File) & Chr(34)
  1209. mciSendString("play " & TheFile, "", 0, 0)
  1210. Exit Sub
  1211. TheError: MsgBox(Err.Description, , " Error")
  1212. End Sub
  1213. Sub MP3Pause()
  1214. TheFile = Chr(34) & Trim(MP3File) & Chr(34)
  1215. Call mciSendString("Stop " & TheFile, CStr(0), 0, 0)
  1216. Exit Sub
  1217. TheError: MsgBox(Err.Description, , " Error")
  1218. End Sub
  1219.  
  1220. Public ReadOnly Property durationInMS() As Integer
  1221.  
  1222. 'get duration of the song in milli-seconds
  1223.  
  1224. Get
  1225.  
  1226. Dim totalTime As String = Space(128)
  1227.  
  1228. mciSendString("status " & TheFile & " length", totalTime, 128, 0)
  1229.  
  1230. _dMS = Val(totalTime)
  1231.  
  1232. durationInMS = _dMS
  1233.  
  1234. totalTime = Nothing
  1235. _dMS = Nothing
  1236.  
  1237. End Get
  1238.  
  1239. End Property
  1240.  
  1241. Public ReadOnly Property durationInSec() As Integer
  1242.  
  1243. 'get the duration of the song in seconds
  1244.  
  1245. Get
  1246.  
  1247. _dSec = durationInMS / 1000
  1248.  
  1249. durationInSec = _dSec
  1250.  
  1251. _dSec = Nothing
  1252.  
  1253. End Get
  1254.  
  1255. End Property
  1256.  
  1257. Public ReadOnly Property formatDuration() As String
  1258.  
  1259. 'get the duration of a song in a user friendly format, ex: 5:54
  1260.  
  1261. Get
  1262.  
  1263. Dim stat As String = Space(128) '128 space string buufer
  1264. Dim totalTime As Integer = Nothing
  1265.  
  1266. mciSendString("set " & TheFile & " time format ms", stat, 128, 0)
  1267. mciSendString("status " & TheFile & " length", stat, 128, 0)
  1268.  
  1269. totalTime = Val(stat)
  1270. _fDur = getThisTime(totalTime)
  1271.  
  1272. formatDuration = _fDur
  1273.  
  1274. stat = Nothing
  1275. totalTime = Nothing
  1276. _fDur = Nothing
  1277.  
  1278. End Get
  1279.  
  1280. End Property
  1281.  
  1282. Public Property positionInMS() As Integer
  1283.  
  1284. 'get the current playing position in milli-seconds
  1285.  
  1286. Get
  1287.  
  1288. Dim stat As String = Space(128) 'buffer with 128 spaces available
  1289.  
  1290. mciSendString("set " & TheFile & " time format milliseconds", 0, 0, 0)
  1291. mciSendString("status " & TheFile & " position", stat, 128, 0)
  1292.  
  1293. _posMS = Val(stat)
  1294.  
  1295. positionInMS = _posMS
  1296.  
  1297. stat = Nothing
  1298. _posMS = Nothing
  1299.  
  1300. End Get
  1301.  
  1302. Set(ByVal Value As Integer)
  1303.  
  1304. Try
  1305.  
  1306. retVal = mciSendString("set " & TheFile & " time format ms", 0, 0, 0)
  1307.  
  1308. If MP3Playing() = False Then
  1309.  
  1310. mciSendString("play " & TheFile & " from " & Value, 0, 0, 0)
  1311.  
  1312. Else
  1313.  
  1314. mciSendString("seek " & TheFile & " to " & Value, 0, 0, 0)
  1315.  
  1316. End If
  1317.  
  1318. Catch exc As Exception
  1319.  
  1320. MessageBox.Show(exc.Message, " Error", MessageBoxButtons.OK)
  1321.  
  1322. End Try
  1323.  
  1324. End Set
  1325.  
  1326.  
  1327. End Property
  1328.  
  1329. Public ReadOnly Property positionInSec() As Integer
  1330.  
  1331. 'get the current playing position in seconds
  1332.  
  1333. Get
  1334. Dim pos As Integer
  1335. _posSec = Val(positionInMS / 1000)
  1336.  
  1337. positionInSec = _posSec
  1338.  
  1339. _posSec = Nothing
  1340.  
  1341. End Get
  1342.  
  1343. End Property
  1344.  
  1345. Public ReadOnly Property formatPosition() As String
  1346.  
  1347. 'get the current playing position in a user-friendly format, ex - 1:12
  1348.  
  1349. Get
  1350.  
  1351. Dim sec As Integer = Nothing
  1352. Dim mins As Integer = Nothing
  1353.  
  1354. sec = Val(positionInSec())
  1355.  
  1356. If sec < 60 Then _fPos = "0:" & Format(sec, "00")
  1357.  
  1358. If sec > 59 Then
  1359.  
  1360. mins = Int(sec / 60)
  1361. sec = sec - (mins * 60)
  1362.  
  1363. _fPos = Format(mins, "0") & ":" & Format(sec, "00")
  1364.  
  1365. End If
  1366.  
  1367. formatPosition = _fPos
  1368.  
  1369. sec = Nothing
  1370. mins = Nothing
  1371. _fPos = Nothing
  1372.  
  1373. End Get
  1374.  
  1375. End Property
  1376.  
  1377. Private Function getThisTime(ByVal timein As Integer) As String
  1378.  
  1379. 'used to format the position and duration propertys to a user friendly
  1380. 'format. ex: :49, 9:02, ect...
  1381.  
  1382. Dim conH As Integer
  1383. Dim conM As Integer
  1384. Dim conS As Integer
  1385. Dim remTime As Integer
  1386. Dim strRetTime As String
  1387.  
  1388. Try
  1389.  
  1390. remTime = timein / 1000
  1391. conH = Int(remTime / 3600)
  1392. remTime = remTime Mod 3600
  1393. conM = Int(remTime / 60)
  1394. remTime = remTime Mod 60
  1395. conS = remTime
  1396.  
  1397. If conH > 0 Then
  1398.  
  1399. strRetTime = Trim(Str(conH)) & ":"
  1400.  
  1401. Else
  1402.  
  1403. strRetTime = ""
  1404.  
  1405. End If
  1406.  
  1407. If conM >= 10 Then
  1408.  
  1409. strRetTime = strRetTime & Trim(Str(conM))
  1410.  
  1411. ElseIf conM > 0 Then
  1412.  
  1413. strRetTime = strRetTime & Trim(Str(conM))
  1414.  
  1415. Else
  1416.  
  1417. strRetTime = strRetTime & "0"
  1418.  
  1419. End If
  1420.  
  1421. strRetTime = strRetTime & ":"
  1422.  
  1423. If conS >= 10 Then
  1424.  
  1425. strRetTime = strRetTime & Trim(Str(conS))
  1426.  
  1427. ElseIf conS > 0 Then
  1428.  
  1429. strRetTime = strRetTime & "0" & Trim(Str(conS))
  1430.  
  1431. Else
  1432.  
  1433. strRetTime = strRetTime & "00"
  1434.  
  1435. End If
  1436.  
  1437. getThisTime = strRetTime
  1438.  
  1439. 'clean up all variables
  1440. conH = Nothing
  1441. conM = Nothing
  1442. conS = Nothing
  1443. remTime = Nothing
  1444. strRetTime = Nothing
  1445.  
  1446. Catch exc As Exception
  1447.  
  1448. MessageBox.Show(exc.Message, " Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
  1449.  
  1450. End Try
  1451.  
  1452. End Function
  1453.  
  1454. Public ReadOnly Property timeRemainingInMS() As Integer
  1455.  
  1456. 'get the time remaining in milli-seconds
  1457.  
  1458. Get
  1459.  
  1460. _tRemainingMS = durationInMS - positionInMS
  1461.  
  1462. timeRemainingInMS = _tRemainingMS
  1463.  
  1464. _tRemainingMS = Nothing
  1465.  
  1466. End Get
  1467.  
  1468. End Property
  1469.  
  1470. Public ReadOnly Property timeRemainingInSec() As Integer
  1471.  
  1472. 'get the time remaining in seconds
  1473.  
  1474. Get
  1475.  
  1476. _tRemainingSec = durationInSec - positionInSec
  1477.  
  1478. timeRemainingInSec = _tRemainingSec
  1479.  
  1480. _tRemainingSec = Nothing
  1481.  
  1482. End Get
  1483.  
  1484. End Property
  1485.  
  1486. Public ReadOnly Property formatTimeRemaining() As String
  1487.  
  1488. 'get the time remaining in a user friendly format - ex. 3:50
  1489.  
  1490. Get
  1491.  
  1492. _fTRemaining = getThisTime(timeRemainingInMS)
  1493.  
  1494. formatTimeRemaining = _fTRemaining
  1495.  
  1496. _fTRemaining = Nothing
  1497.  
  1498. End Get
  1499.  
  1500. End Property
  1501.  
  1502. Public Property volumeLevel() As Integer
  1503.  
  1504. 'set - the sound volume level
  1505. 'get - the current sound volume level value
  1506. '
  1507. 'note: 1000 = max volume | 0 = minimum volume value
  1508.  
  1509. Get
  1510.  
  1511. Dim theLevel As String = Space(128) '128 space buffer
  1512.  
  1513. mciSendString("status " & TheFile & " volume", theLevel, 128, 0)
  1514.  
  1515. _volLevel = Val(theLevel)
  1516.  
  1517. volumeLevel = _volLevel
  1518.  
  1519. theLevel = Nothing
  1520. _volLevel = Nothing
  1521.  
  1522. End Get
  1523.  
  1524. Set(ByVal Value As Integer)
  1525.  
  1526. mciSendString("setaudio " & TheFile & " volume to " & Value, 0, 0, 0)
  1527.  
  1528. End Set
  1529.  
  1530. End Property
  1531.  
  1532. Public Property muteSoundOutput() As Boolean
  1533.  
  1534. 'set - turn the sound on or off
  1535. 'get - check if the sound is on or off
  1536.  
  1537. Get
  1538.  
  1539. muteSoundOutput = _muteOutput
  1540.  
  1541. End Get
  1542.  
  1543. Set(ByVal Value As Boolean)
  1544.  
  1545. If Value = True Then
  1546.  
  1547. mciSendString("setaudio " & TheFile & " off", 0, 0, 0)
  1548.  
  1549. _muteOutput = Value
  1550.  
  1551. Else
  1552.  
  1553. mciSendString("setaudio " & TheFile & " on", 0, 0, 0)
  1554.  
  1555. _muteOutput = Value
  1556.  
  1557. End If
  1558.  
  1559. End Set
  1560.  
  1561. End Property
  1562.  
  1563.  
  1564.  
  1565. End Class
  1566.  
  1567. vb.net volume meter :
  1568.  
  1569. contians the walkthrough to get volume meter level at realtime from a usb microphone. also you can search wikipedia
  1570. for speech recognition.
  1571.  
  1572. here is the vumeter tutorial incase the link gives you problems:
  1573.  
  1574. 'start of tutorial
  1575.  
  1576. Introduction
  1577. volume meter in vb.net tested working gets the audio level from usb microphone (in 2 channels)
  1578.  
  1579. at realtime
  1580.  
  1581. utilizing directx
  1582.  
  1583. tested on vb 2008 express edition win xp pro sp3 .net 3.5
  1584.  
  1585. Background
  1586. the credit goes to 2 very good programers :
  1587. 1 nigel ealand, who evolved the code to work in vb 2008
  1588. 2 jacob klint the original poster of the code in codeguru at the link:
  1589. http://www.codeproject.com/KB/direct...87#xx3514687xx
  1590.  
  1591. Using the code
  1592. form controls (designer) :
  1593. 1 ComboBox name : ComboBox1
  1594. 2 button name : FindButton
  1595. 3 button name : StartButton
  1596. 4 progressbar name : ProgressBar1 maximum : 32770
  1597. 5 progressbar name : ProgressBar2 maximum : 32770
  1598.  
  1599. download directx 9 sdk from the link :
  1600. http://www.microsoft.com/downloads/d...displaylang=en[^]
  1601.  
  1602. install, restart comuter, connect usb microphone with drivers installed from its cd (auto plug n play install might not suffice)
  1603.  
  1604. paste source code (in the end of this text) or
  1605.  
  1606. sln file : http://www.esac.org.uk/VUTest.zip[^] if your lazy
  1607.  
  1608. project, add reference, .net, microsoft.directx.sound
  1609.  
  1610. disabling loader lock error (debug, exeptions, managed debuging assistants,
  1611. uncheck loader lock (thrown))
  1612. if not unchecked press debug again after exeption will have been thrown
  1613.  
  1614. Imports System
  1615. Imports System.Collections
  1616. Imports System.ComponentModel
  1617. Imports System.Drawing
  1618. Imports System.Windows.Forms
  1619. Imports Microsoft.DirectX.DirectSound
  1620. Imports System.Threading
  1621. Imports System.Collections.Specialized
  1622. Public Class Sound_Card_Form
  1623. Private Sub StartButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles FindButton.Click
  1624. 'Dim MyVU As New VolumeMeter
  1625. 'MyVU.Start()
  1626. Start()
  1627. End Sub
  1628. Private Sub FindButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles FindButton.Click
  1629. 'Dim MyVU As New VolumeMeter
  1630. 'MyVU.FindDevices()
  1631. FindDevices()
  1632. End Sub
  1633.  
  1634. ' Public Class VolumeMeter
  1635. 'Inherits System.Windows.Forms.UserControl
  1636. 'Public Delegate Sub VolumeChangedEventHandler(ByVal vcea As VolumeChangedEventArgs)
  1637. 'Public Event VolumeChanged As VolumeChangedEventHandler
  1638. Private Const SAMPLES As Integer = 8
  1639. Private Shared SAMPLE_FORMAT_ARRAY As Integer() = {SAMPLES, 2, 1}
  1640. Public Shared audioDevices As CaptureDevicesCollection
  1641. Private Shared m_deviceNames As StringCollection
  1642. Private deviceName As String = "(none)"
  1643. Private deviceIndex As Integer = -1
  1644. Private buffer As Microsoft.DirectX.DirectSound.CaptureBuffer
  1645. Private liveVolumeThread As System.Threading.Thread
  1646. Private m_sampleDelay As Integer = 100
  1647. Private m_frameDelay As Integer = 10
  1648. Private m_autoStart As Boolean = True
  1649. 'Private components As System.ComponentModel.Container = Nothing
  1650. Public Sub FindDevices()
  1651. Dim audioDevices As New CaptureDevicesCollection
  1652. Dim x As Integer = 0
  1653. While x < audioDevices.Count
  1654. ComboBox1.Items.Add(audioDevices.Item(x).Description)
  1655. x = x + 1
  1656. End While
  1657. ComboBox1.SelectedIndex = 0
  1658. End Sub
  1659. Public Sub Start()
  1660. [Stop]()
  1661. Dim audioDevices As New CaptureDevicesCollection
  1662. deviceIndex = ComboBox1.SelectedIndex
  1663. If deviceIndex <> -1 Then
  1664. ' initialize the capture buffer and start the animation thread
  1665. Dim cap As New Capture(audioDevices(deviceIndex).DriverGuid)
  1666. Dim desc As New CaptureBufferDescription()
  1667. Dim wf As New WaveFormat()
  1668. wf.BitsPerSample = 16
  1669. wf.SamplesPerSecond = 44100
  1670. wf.Channels = 2
  1671. wf.BlockAlign = CShort(wf.Channels * wf.BitsPerSample / 8)
  1672. wf.AverageBytesPerSecond = wf.BlockAlign * wf.SamplesPerSecond
  1673. wf.FormatTag = WaveFormatTag.Pcm
  1674. desc.Format = wf
  1675. desc.BufferBytes = SAMPLES * wf.BlockAlign
  1676. buffer = New Microsoft.DirectX.DirectSound.CaptureBuffer(desc, cap)
  1677. buffer.Start(True)
  1678. ' Start a seperate thread to read the buffer and update the progress bars
  1679. liveVolumeThread = New Thread(AddressOf updateProgress) 'Thread starts at updateProgress
  1680. Control.CheckForIllegalCrossThreadCalls = False ' This is needed otherwise the form will not update
  1681. liveVolumeThread.Priority = ThreadPriority.Lowest ' Thread works in the background
  1682. liveVolumeThread.Start()
  1683. End If
  1684. End Sub
  1685. Public Sub [Stop]()
  1686. If liveVolumeThread IsNot Nothing Then
  1687. liveVolumeThread.Abort()
  1688. liveVolumeThread.Join()
  1689. liveVolumeThread = Nothing
  1690. End If
  1691. If buffer IsNot Nothing Then
  1692. If buffer.Capturing Then
  1693. buffer.[Stop]()
  1694. End If
  1695. buffer.Dispose()
  1696. buffer = Nothing
  1697. End If
  1698. End Sub
  1699.  
  1700. Public Sub updateProgress()
  1701. While True
  1702. Dim tempFrameDelay As Integer = m_frameDelay
  1703. Dim tempSampleDelay As Integer = m_sampleDelay
  1704. Dim samples__1 As Array = buffer.Read(0, GetType(Int16), LockFlag.FromWriteCursor, SAMPLE_FORMAT_ARRAY)
  1705. ' for each channel, determine the step size necessary for each iteration
  1706. Dim leftGoal As Integer = 0
  1707. Dim rightGoal As Integer = 0
  1708. ' Sum the 8 samples
  1709. For i As Integer = 0 To SAMPLES - 1
  1710. leftGoal += CType(samples__1.GetValue(i, 0, 0), Int16)
  1711. rightGoal += CType(samples__1.GetValue(i, 1, 0), Int16)
  1712. Next
  1713. ' Calculate the average of the 8 samples
  1714. leftGoal = CInt(Math.Abs(leftGoal \ SAMPLES))
  1715. rightGoal = CInt(Math.Abs(rightGoal \ SAMPLES))
  1716. Dim range1 As Double = leftGoal - ProgressBar1.Value ' calculates the difference between new and the current progress bar value
  1717. Dim range2 As Double = rightGoal - ProgressBar2.Value
  1718. ' Assign the exact current value to the progress bar
  1719. Dim exactValue1 As Double = ProgressBar1.Value
  1720. Dim exactValue2 As Double = ProgressBar2.Value
  1721. Dim stepSize1 As Double = range1 / tempSampleDelay * tempFrameDelay
  1722. ' Limit the value range to positive values
  1723. If Math.Abs(stepSize1) < 0.01 Then
  1724. stepSize1 = Math.Sign(range1) * 0.01
  1725. End If
  1726. Dim absStepSize1 As Double = Math.Abs(stepSize1)
  1727. Dim stepSize2 As Double = range2 / tempSampleDelay * tempFrameDelay
  1728. If Math.Abs(stepSize2) < 0.01 Then
  1729. stepSize2 = Math.Sign(range2) * 0.01
  1730. End If
  1731. Dim absStepSize2 As Double = Math.Abs(stepSize2)
  1732. ' increment/decrement the bars' values until both equal their desired goals,
  1733. ' sleeping between iterations
  1734. If (ProgressBar1.Value = leftGoal) AndAlso (ProgressBar2.Value = rightGoal) Then
  1735. Thread.Sleep(tempSampleDelay)
  1736. Else
  1737. Do
  1738. If ProgressBar1.Value <> leftGoal Then
  1739. If absStepSize1 < Math.Abs(leftGoal - ProgressBar1.Value) Then
  1740. exactValue1 += stepSize1
  1741. ProgressBar1.Value = CInt(Math.Truncate(Math.Round(exactValue1)))
  1742. 'This is the real value
  1743. 'decibels = 20 * Log10(ProgressBar1.Value/ 32768.0)
  1744. Else
  1745. ProgressBar1.Value = leftGoal
  1746. End If
  1747. End If
  1748. If ProgressBar2.Value <> rightGoal Then
  1749. If absStepSize2 < Math.Abs(rightGoal - ProgressBar2.Value) Then
  1750. exactValue2 += stepSize2
  1751. ProgressBar2.Value = CInt(Math.Truncate(Math.Round(exactValue2)))
  1752. Else
  1753. ProgressBar2.Value = rightGoal
  1754. End If
  1755. End If
  1756. Thread.Sleep(tempFrameDelay)
  1757. Loop While (ProgressBar1.Value <> leftGoal) OrElse (ProgressBar2.Value <> rightGoal)
  1758. End If
  1759. End While
  1760. End Sub
  1761.  
  1762. End Class
  1763.  
  1764. run : press button 1 , press button 2
  1765.  
  1766. Points of Interest
  1767. samples delay variables (in source code) :
  1768. Private m_sampleDelay As Integer = 15 ' miliseconds
  1769. Private m_frameDelay As Integer = 15
  1770.  
  1771. look up in youtube: vb.net volume meter
  1772.  
  1773. 'end of tutorial
  1774.  
  1775. you can delete :
  1776. Imports System.Collections
  1777. Imports System.ComponentModel
  1778. Imports System.Drawing
  1779. Imports System.Windows.Forms
  1780.  
  1781. microphones cd drivers need to be installed.
  1782.  
  1783. take your time, this king of thing requires lazyness.
  1784.  
  1785. GET JOYSTICK ARROWS PRESSED : (BY jo0ls)
  1786.  
  1787.  
  1788. Create a new windows forms application.
  1789. Use Project -> Add class to add a new class called "Joystick.vb"
  1790. In the Joystick.vb code file, replace the existing code with the following:
  1791. Imports System.ComponentModel
  1792. Imports System.Runtime.InteropServices
  1793.  
  1794. Public Class Joystick
  1795. Inherits NativeWindow
  1796.  
  1797. Private parent As Form
  1798. Private Const MM_JOY1MOVE As Integer = &H3A0
  1799.  
  1800. ' Public Event Move(ByVal joystickPosition As Point)
  1801. Public btnValue As String
  1802. Public Event Up()
  1803. Public Event Down()
  1804. Public Event Left()
  1805. Public Event Right()
  1806.  
  1807. <StructLayout(LayoutKind.Explicit)> _
  1808. Private Structure JoyPosition
  1809. <FieldOffset(0)> _
  1810. Public Raw As IntPtr
  1811. <FieldOffset(0)> _
  1812. Public XPos As UShort
  1813. <FieldOffset(2)> _
  1814. Public YPos As UShort
  1815. End Structure
  1816.  
  1817. Private Class NativeMethods
  1818.  
  1819. Private Sub New()
  1820. End Sub
  1821.  
  1822. ' This is a "Stub" function - it has no code in its body.
  1823. ' There is a similarly named function inside a dll that comes with windows called
  1824. ' winmm.dll.
  1825. ' The .Net framework will route calls to this function, through to the dll file.
  1826. <DllImport("winmm", CallingConvention:=CallingConvention.Winapi, EntryPoint:="joySetCapture", SetLastError:=True)> _
  1827. Public Shared Function JoySetCapture(ByVal hwnd As IntPtr, ByVal uJoyID As Integer, ByVal uPeriod As Integer, <MarshalAs(UnmanagedType.Bool)> ByVal changed As Boolean) As Integer
  1828. End Function
  1829.  
  1830. End Class
  1831.  
  1832. Public Sub New(ByVal parent As Form, ByVal joyId As Integer)
  1833. AddHandler parent.HandleCreated, AddressOf Me.OnHandleCreated
  1834. AddHandler parent.HandleDestroyed, AddressOf Me.OnHandleDestroyed
  1835. AssignHandle(parent.Handle)
  1836. Me.parent = parent
  1837. Dim result As Integer = NativeMethods.JoySetCapture(Me.Handle, joyId, 100, True)
  1838. End Sub
  1839.  
  1840. Private Sub OnHandleCreated(ByVal sender As Object, ByVal e As EventArgs)
  1841. AssignHandle(DirectCast(sender, Form).Handle)
  1842. End Sub
  1843.  
  1844. Private Sub OnHandleDestroyed(ByVal sender As Object, ByVal e As EventArgs)
  1845. ReleaseHandle()
  1846. End Sub
  1847.  
  1848. Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
  1849. If m.Msg = MM_JOY1MOVE Then
  1850. ' Joystick co-ords.
  1851. ' (0,0) (32768,0) (65535, 0)
  1852. '
  1853. '
  1854. '
  1855. ' (0, 32768) (32768, 32768) (65535, 32768)
  1856. '
  1857. '
  1858. '
  1859. '
  1860. ' (0, 65535) (32768, 65535) (65535, 65535)
  1861. '
  1862. Dim p As JoyPosition
  1863. p.Raw = m.LParam
  1864. ' RaiseEvent Move(New Point(p.XPos, p.YPos))
  1865. If p.XPos > 16384 AndAlso p.XPos < 49152 Then
  1866. ' X is near the centre line.
  1867. If p.YPos < 6000 Then
  1868. ' Y is near the top.
  1869. RaiseEvent Up()
  1870. ElseIf p.YPos > 59536 Then
  1871. ' Y is near the bottom.
  1872. RaiseEvent Down()
  1873. End If
  1874. Else
  1875. If p.YPos > 16384 AndAlso p.YPos < 49152 Then
  1876. ' Y is near the centre line
  1877. If p.XPos < 6000 Then
  1878. ' X is near the left.
  1879. RaiseEvent Left()
  1880. ElseIf p.XPos > 59536 Then
  1881. ' X is near the right
  1882. RaiseEvent Right()
  1883. End If
  1884. End If
  1885. End If
  1886. End If
  1887. If btnValue <> m.WParam.ToString Then
  1888. btnValue = m.WParam.ToString
  1889. End If
  1890. MyBase.WndProc(m)
  1891. End Sub
  1892.  
  1893. End Class
  1894. Now you can ignore the Joystick.vb code - you aren't supposed to be able to understand it on day 3 of learning VB.Net. Maybe on day 303...
  1895. Now you can create an instance of the Joystick class in your Form1 class, and handle the events:
  1896. add a timer and a label from the toolbox (in form1.vb[design] window)
  1897. Public Class Form1
  1898.  
  1899. ' This declares what Type the variable joystick1 will be for. The Type is Joystick.
  1900. ' WithEvents allows you to easily add events using the IDE.
  1901. Private WithEvents joystick1 As Joystick
  1902.  
  1903. ' This is an event that belongs to the Form. It is raised when the form loads.
  1904. Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  1905. ' Here we create the Joystick object. You must pass Me - which refers to this Form,
  1906. ' and 0 - which is the Joystick id.
  1907. joystick1 = New Joystick(Me, 0)
  1908. End Sub
  1909.  
  1910. ' And now we have the four events that belong to joystick1.
  1911.  
  1912. Private Sub joystick1_Down() Handles joystick1.Down
  1913. ' TODO: Replace this so that it plays a sound instead.
  1914. Me.Text = "Down"
  1915. End Sub
  1916.  
  1917. Private Sub joystick1_Left() Handles joystick1.Left
  1918. ' TODO: Replace this so that it plays a sound instead.
  1919. Me.Text = "Left"
  1920. End Sub
  1921.  
  1922. Private Sub joystick1_Right() Handles joystick1.Right
  1923. ' TODO: Replace this so that it plays a sound instead.
  1924. Me.Text = "Right"
  1925. End Sub
  1926.  
  1927. Private Sub joystick1_Up() Handles joystick1.Up
  1928. ' TODO: Replace this so that it plays a sound instead.
  1929. Me.Text = "Up"
  1930. End Sub
  1931. ' Private Sub joystick1_buttonPressed() Handles joystick1.buttonPressed
  1932. ' TODO: Replace this so that it plays a sound instead.
  1933. ' Me.Text = joystick1.b1
  1934. 'End Sub
  1935.  
  1936. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  1937. Label1.Text = joystick1.btnValue
  1938. End Sub
  1939. End Class
  1940.  
  1941. A STRONG ENCRYPTION CLASS
  1942.  
  1943. by Jenner :
  1944.  
  1945. The first two simply encrypt and decrypt strings. You just provide the "key".
  1946. The third turns a string into a hash. Very useful for passwords.
  1947. The last compares a string against a hash. Perfect for login screens
  1948.  
  1949. Imports System.Security.Cryptography
  1950. Imports System.IO
  1951. Imports System.Text
  1952.  
  1953. Public Class clsCrypto
  1954. 'Byte vector required for Rijndael. This is randomly generated and recommended you change it on a per-application basis.
  1955. 'It is 16 bytes.
  1956. Private bytIV() As Byte = {121, 241, 10, 1, 132, 74, 11, 39, 255, 91, 45, 78, 14, 211, 22, 62}
  1957.  
  1958. 'Character to pad keys with to make them at least intMinKeySize.
  1959. Private Const chrKeyFill As Char = "X"c
  1960.  
  1961. 'String to display on error for functions that return strings. {0} is Exception.Message.
  1962. Private Const strTextErrorString As String = "#ERROR - {0}"
  1963.  
  1964. 'Min size in bytes of randomly generated salt.
  1965. Private Const intMinSalt As Integer = 4
  1966.  
  1967. 'Max size in bytes of randomly generated salt.
  1968. Private Const intMaxSalt As Integer = 8
  1969.  
  1970. 'Size in bytes of Hash result. MD5 returns a 128 bit hash.
  1971. Private Const intHashSize As Integer = 16
  1972.  
  1973. 'Size in bytes of the key length. Rijndael takes either a 128, 192, or 256 bit key.
  1974. 'If it is under this, pad with chrKeyFill. If it is over this, truncate to the length.
  1975. Private Const intKeySize As Integer = 32
  1976.  
  1977. 'Encrypt a String with Rijndael symmetric encryption.
  1978. Public Function EncryptString128Bit(ByVal strPlainText As String, ByVal strKey As String) As String
  1979. Try
  1980. Dim bytPlainText() As Byte
  1981. Dim bytKey() As Byte
  1982. Dim bytEncoded() As Byte
  1983. Dim objMemoryStream As New MemoryStream
  1984. Dim objRijndaelManaged As New RijndaelManaged
  1985.  
  1986. strPlainText = strPlainText.Replace(vbNullChar, String.Empty)
  1987.  
  1988. bytPlainText = Encoding.UTF8.GetBytes(strPlainText)
  1989. bytKey = ConvertKeyToBytes(strKey)
  1990.  
  1991. Dim objCryptoStream As New CryptoStream(objMemoryStream, _
  1992. objRijndaelManaged.CreateEncryptor(bytKey, bytIV), _
  1993. CryptoStreamMode.Write)
  1994.  
  1995. objCryptoStream.Write(bytPlainText, 0, bytPlainText.Length)
  1996. objCryptoStream.FlushFinalBlock()
  1997.  
  1998. bytEncoded = objMemoryStream.ToArray
  1999. objMemoryStream.Close()
  2000. objCryptoStream.Close()
  2001.  
  2002. Return Convert.ToBase64String(bytEncoded)
  2003. Catch ex As Exception
  2004. Return String.Format(strTextErrorString, ex.Message)
  2005. End Try
  2006. End Function
  2007.  
  2008. 'Decrypt a String with Rijndael symmetric encryption.
  2009. Public Function DecryptString128Bit(ByVal strCryptText As String, ByVal strKey As String) As String
  2010. Try
  2011. Dim bytCryptText() As Byte
  2012. Dim bytKey() As Byte
  2013.  
  2014. Dim objRijndaelManaged As New RijndaelManaged
  2015.  
  2016. bytCryptText = Convert.FromBase64String(strCryptText)
  2017. bytKey = ConvertKeyToBytes(strKey)
  2018.  
  2019. Dim bytTemp(bytCryptText.Length) As Byte
  2020. Dim objMemoryStream As New MemoryStream(bytCryptText)
  2021.  
  2022. Dim objCryptoStream As New CryptoStream(objMemoryStream, _
  2023. objRijndaelManaged.CreateDecryptor(bytKey, bytIV), _
  2024. CryptoStreamMode.Read)
  2025.  
  2026. objCryptoStream.Read(bytTemp, 0, bytTemp.Length)
  2027.  
  2028. objMemoryStream.Close()
  2029. objCryptoStream.Close()
  2030.  
  2031. Return Encoding.UTF8.GetString(bytTemp).Replace(vbNullChar, String.Empty)
  2032.  
  2033. Catch ex As Exception
  2034. Return String.Format(strTextErrorString, ex.Message)
  2035. End Try
  2036.  
  2037. End Function
  2038.  
  2039. 'Compute an MD5 hash code from a string and append any salt-bytes used/generated to the end.
  2040. Public Function ComputeMD5Hash(ByVal strPlainText As String, Optional ByVal bytSalt() As Byte = Nothing) As String
  2041. Try
  2042. Dim bytPlainText As Byte() = Encoding.UTF8.GetBytes(strPlainText)
  2043. Dim hash As HashAlgorithm = New MD5CryptoServiceProvider()
  2044.  
  2045. If bytSalt Is Nothing Then
  2046. Dim rand As New Random
  2047. Dim intSaltSize As Integer = rand.Next(intMinSalt, intMaxSalt)
  2048.  
  2049. bytSalt = New Byte(intSaltSize - 1) {}
  2050.  
  2051. Dim rng As New RNGCryptoServiceProvider
  2052. rng.GetNonZeroBytes(bytSalt)
  2053. End If
  2054.  
  2055. Dim bytPlainTextWithSalt() As Byte = New Byte(bytPlainText.Length + bytSalt.Length - 1) {}
  2056.  
  2057. bytPlainTextWithSalt = ConcatBytes(bytPlainText, bytSalt)
  2058.  
  2059. Dim bytHash As Byte() = hash.ComputeHash(bytPlainTextWithSalt)
  2060. Dim bytHashWithSalt() As Byte = New Byte(bytHash.Length + bytSalt.Length - 1) {}
  2061.  
  2062. bytHashWithSalt = ConcatBytes(bytHash, bytSalt)
  2063.  
  2064. Return Convert.ToBase64String(bytHashWithSalt)
  2065. Catch ex As Exception
  2066. Return String.Format(strTextErrorString, ex.Message)
  2067. End Try
  2068. End Function
  2069.  
  2070. 'Verify a string against a hash generated with the ComputeMD5Hash function above.
  2071. Public Function VerifyHash(ByVal strPlainText As String, ByVal strHashValue As String) As Boolean
  2072. Try
  2073. Dim bytWithSalt As Byte() = Convert.FromBase64String(strHashValue)
  2074.  
  2075. If bytWithSalt.Length < intHashSize Then Return False
  2076.  
  2077. Dim bytSalt() As Byte = New Byte(bytWithSalt.Length - intHashSize - 1) {}
  2078.  
  2079. Array.Copy(bytWithSalt, intHashSize, bytSalt, 0, bytWithSalt.Length - intHashSize)
  2080.  
  2081. Dim strExpectedHashString As String = ComputeMD5Hash(strPlainText, bytSalt)
  2082.  
  2083. Return strHashValue.Equals(strExpectedHashString)
  2084. Catch ex As Exception
  2085. Return Nothing
  2086. End Try
  2087. End Function
  2088.  
  2089. 'Simple function to concatenate two byte arrays.
  2090. Private Function ConcatBytes(ByVal bytA() As Byte, ByVal bytB() As Byte) As Byte()
  2091. Try
  2092. Dim bytX() As Byte = New Byte(((bytA.Length + bytB.Length)) - 1) {}
  2093.  
  2094. Array.Copy(bytA, bytX, bytA.Length)
  2095. Array.Copy(bytB, 0, bytX, bytA.Length, bytB.Length)
  2096.  
  2097. Return bytX
  2098. Catch ex As Exception
  2099. Return Nothing
  2100. End Try
  2101.  
  2102. End Function
  2103.  
  2104. 'A function to convert a string into a 32 byte key.
  2105. Private Function ConvertKeyToBytes(ByVal strKey As String) As Byte()
  2106. Try
  2107. Dim intLength As Integer = strKey.Length
  2108.  
  2109. If intLength < intKeySize Then
  2110. strKey &= Strings.StrDup(intKeySize - intLength, chrKeyFill)
  2111. Else
  2112. strKey = strKey.Substring(0, intKeySize)
  2113. End If
  2114.  
  2115. Return Encoding.UTF8.GetBytes(strKey)
  2116. Catch ex As Exception
  2117. Return Nothing
  2118. End Try
  2119. End Function
  2120.  
  2121. End Class
  2122.  
Add Comment
Please, Sign In to add comment