cagueca Posted March 12, 2009 at 02:28 AM Report Share #250079 Posted March 12, 2009 at 02:28 AM Boas : Depois de converter um codigo de c# para vb.net da me um erro .. "Namespace statements can occur only at file or namespace level" Ja resolvi os outros erros que dava mas este ja experimentei declarar noutro sitio do codigo mas depois da me mais erros ... Alguem pode explicar como posso resolver isto ?? Obrigado EDIT: Alterado título Link to comment Share on other sites More sharing options...
jpaulino Posted March 12, 2009 at 07:13 AM Report Share #250082 Posted March 12, 2009 at 07:13 AM Lê isto http://msdn.microsoft.com/en-us/library/f8za39hx(VS.80).aspx e se não conseguires mostra o código Link to comment Share on other sites More sharing options...
cagueca Posted March 12, 2009 at 11:57 AM Author Report Share #250204 Posted March 12, 2009 at 11:57 AM Boas : Ja tinha lido isso .. mas nem assim desculpa .. Codigo ... Imports System Imports System.Collections.Generic Imports System.ComponentModel Imports System.Data Imports System.Drawing Imports System.Text Imports System.Windows.Forms Imports System.Diagnostics Imports System.IO Imports System.Media Imports System.Net.NetworkInformation Imports System.Text.RegularExpressions Imports System.Management Imports System.Net.Sockets Public Class wififind Private Sub wififind_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub ' Procurar redes wireless Private Sub procurabtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles procurabtn.Click End Sub Namespace wififind ' AQUI E ONDE ESTA O ERRO.. Partial Public Class Form1 Inherits Form Public Sub New() InitializeComponent() End Sub Private Sub timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Scan() End Sub Private Sub Scan() Dim output As String Dim line As String Dim BSSIDNumber As Integer = 0 Dim NetworkIndex As Integer = -1 Dim Networks As String(,) = New String(100, 9) {} ListView1.SmallImageList = imageSignalLevel Dim proc As New Process() proc.StartInfo.CreateNoWindow = True proc.StartInfo.FileName = "netsh" proc.StartInfo.Arguments = "wlan show networks mode=bssid" proc.StartInfo.RedirectStandardOutput = True proc.StartInfo.UseShellExecute = False ' required for the Redirect setting above Process.Start(proc); proc.Start() output = proc.StandardOutput.ReadToEnd() proc.WaitForExit() Dim sr As New StringReader(output.ToString()) line = Nothing While (line = sr.ReadLine()) <> Nothing If line.StartsWith("General Failure") Then ' Wifi disconnected or not installed Exit While End If If line.StartsWith("SSID") Then System.Math.Max(System.Threading.Interlocked.Increment(NetworkIndex), NetworkIndex - 1) Dim i As Integer = 0 While i < 9 ' prevent exception finding null on search Networks(NetworkIndex, i) = " " System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1) End While Networks(NetworkIndex, 3) = "0%" ' prevent exception for trim BSSIDNumber = 0 ' reset the BSSID number Networks(NetworkIndex, 1) = line.Substring(line.IndexOf(":") + 1).TrimEnd(" "c).TrimStart(" "c) Continue While End If If line.IndexOf("Network type") > 0 Then If line.EndsWith("Infrastructure") Then Networks(NetworkIndex, 7) = "AP" Continue While Else '"Ad-hoc"; Networks(NetworkIndex, 7) = line.Substring(line.IndexOf(":") + 1) End If End If If line.IndexOf("Authentication") > 0 Then Networks(NetworkIndex, 4) = line.Substring(line.IndexOf(":") + 1).TrimStart(" "c).TrimEnd(" "c) Continue While End If If line.IndexOf("Encryption") > 0 Then Networks(NetworkIndex, 5) = line.Substring(line.IndexOf(":") + 1).TrimStart(" "c).TrimEnd(" "c) Continue While End If If line.IndexOf("BSSID") > 0 Then If (Convert.ToInt32(line.IndexOf("BSSID" + 6)) > BSSIDNumber) Then BSSIDNumber = Convert.ToInt32(line.IndexOf("BSSID" + 6)) System.Math.Max(System.Threading.Interlocked.Increment(NetworkIndex), NetworkIndex - 1) Networks(NetworkIndex, 1) = Networks(NetworkIndex - 1, 1) ' same SSID Networks(NetworkIndex, 7) = Networks(NetworkIndex - 1, 7) ' same Network Type Networks(NetworkIndex, 4) = Networks(NetworkIndex - 1, 4) ' Same authorization ' same encryption Networks(NetworkIndex, 5) = Networks(NetworkIndex - 1, 5) End If Networks(NetworkIndex, 0) = line.Substring(line.IndexOf(":") + 1) Continue While End If If line.IndexOf("Signal") > 0 Then Networks(NetworkIndex, 3) = line.Substring(line.IndexOf(":") + 1) Continue While End If If line.IndexOf("Radio Type") > 0 Then Networks(NetworkIndex, 6) = line.Substring(line.IndexOf(":") + 1) Continue While End If If line.IndexOf("Channel") > 0 Then Networks(NetworkIndex, 2) = line.Substring(line.IndexOf(":") + 1) Continue While End If If line.IndexOf("Basic Rates") > 0 Then 'Networks[NetworkIndex, 8] = line.Substring(line.Length - 2, 2); Networks(NetworkIndex, 8) = line.Substring(line.IndexOf(":")) If Networks(NetworkIndex, 8) = ":" Then Networks(NetworkIndex, 8) = "not shown" Continue While End If Networks(NetworkIndex, 8) = Networks(NetworkIndex, 8).TrimStart(":"c).TrimStart(" "c).TrimEnd(" "c) Dim i As Integer = Networks(NetworkIndex, 8).Length - 1 While i > 0 If Networks(NetworkIndex, 8).Substring(i, 1) = " " Then Networks(NetworkIndex, 8) = Networks(NetworkIndex, 8).Substring(i + 1, Networks(NetworkIndex, 8).Length - 1 - i) Exit While End If System.Math.Max(System.Threading.Interlocked.Decrement(i), i + 1) End While End If If line.IndexOf("Other Rates") > 0 Then ' overwrite the basic rates if this entry is present Networks(NetworkIndex, 8) = line.Substring(line.IndexOf(":")) If Networks(NetworkIndex, 8) = ":" Then Networks(NetworkIndex, 8) = "not shown" Continue While End If Networks(NetworkIndex, 8) = Networks(NetworkIndex, 8).TrimStart(":"c).TrimStart(" "c).TrimEnd(" "c) Dim i As Integer = Networks(NetworkIndex, 8).Length - 1 While i >= 0 If Networks(NetworkIndex, 8).Substring(i, 1) = " " Then Networks(NetworkIndex, 8) = Networks(NetworkIndex, 8).Substring(i + 1, Networks(NetworkIndex, 8).Length - 1 - i) Exit While End If System.Math.Max(System.Threading.Interlocked.Decrement(i), i + 1) End While End If End While Dim i As Integer = 0 While i < ListView1.Items.Count ' set signal to zero on all items in list ListView1.Items(i).SubItems(3).Text = "0%" ListView1.Items(i).ImageIndex = 5 System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1) End While Dim i As Integer = 0 While i < NetworkIndex + 1 Dim SearchItem As New ListViewItem() If Networks(i, 0) = " " Then Continue While End If ' don't search if no valid MAC Address ! SearchItem = ListView1.FindItemWithText(Networks(i, 0)) If SearchItem = Nothing Then ' New discovery - add it to the list SystemSounds.Hand.Play() ListView1.Items.Add(Networks(i, 0)) ' MAC Address ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(Networks(i, 1)) ' SSID ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(Networks(i, 2)) ' Channel ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(Networks(i, 3)) ' Signal ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(Networks(i, 4)) ' Authenticatiopn ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(Networks(i, 5)) ' Encryption ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(Networks(i, 6)) ' Radio Type ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(Networks(i, 7)) ' Network Type ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(Networks(i, 8)) ' Speed Dim SignalInt As Integer = Convert.ToInt32(Networks(i, 3).TrimEnd(" "c).TrimEnd("%"c)) If SignalInt > 50 Then ListView1.Items(ListView1.Items.Count - 1).ImageIndex = 0 ElseIf SignalInt > 40 Then ListView1.Items(ListView1.Items.Count - 1).ImageIndex = 1 ElseIf SignalInt > 30 Then ListView1.Items(ListView1.Items.Count - 1).ImageIndex = 2 ElseIf SignalInt > 20 Then ListView1.Items(ListView1.Items.Count - 1).ImageIndex = 3 ElseIf SignalInt > 0 Then ListView1.Items(ListView1.Items.Count - 1).ImageIndex = 4 End If If (Networks(i, 4) = "Open") And (Networks(i, 5) = "None") Then ListView1.Items(ListView1.Items.Count - 1).BackColor = Color.PaleGreen End If ListView1.Items(ListView1.Items.Count - 1).EnsureVisible() Else ' Already in list - update Signal and other details that may change ListView1.Items(SearchItem.Index).SubItems(3).Text = Networks(i, 3) ' Signal ' Don't change any details if blank If Networks(i, 1) <> Nothing Then ListView1.Items(SearchItem.Index).SubItems(1).Text = Networks(i, 1) End If ' SSID If Networks(i, 4) <> Nothing Then ListView1.Items(SearchItem.Index).SubItems(4).Text = Networks(i, 4) End If ' Authenticatiopn If Networks(i, 5) <> Nothing Then ListView1.Items(SearchItem.Index).SubItems(5).Text = Networks(i, 5) End If ' Encryption If Networks(i, 6) <> Nothing Then ListView1.Items(SearchItem.Index).SubItems(6).Text = Networks(i, 6) End If ' Radio Type If Networks(i, 7) <> Nothing Then ListView1.Items(SearchItem.Index).SubItems(7).Text = Networks(i, 7) End If ' Network Type If Networks(i, 8) <> Nothing Then ListView1.Items(SearchItem.Index).SubItems(8).Text = Networks(i, 8) End If ' Speed Dim SignalInt As Integer = Convert.ToInt32(Networks(i, 3).TrimEnd(" "c).TrimEnd("%"c)) If SignalInt > 50 Then ListView1.Items(SearchItem.Index).ImageIndex = 0 ElseIf SignalInt > 40 Then ListView1.Items(SearchItem.Index).ImageIndex = 1 ElseIf SignalInt > 30 Then ListView1.Items(SearchItem.Index).ImageIndex = 2 ElseIf SignalInt > 20 Then ListView1.Items(SearchItem.Index).ImageIndex = 3 ElseIf SignalInt > 0 Then ListView1.Items(SearchItem.Index).ImageIndex = 4 ElseIf SignalInt = 0 Then ListView1.Items(SearchItem.Index).ImageIndex = 5 End If End If System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1) End While End Sub Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) End Sub End Class End Namespace Obrigado desde ja .. Link to comment Share on other sites More sharing options...
Hellblazer Posted March 12, 2009 at 12:01 PM Report Share #250210 Posted March 12, 2009 at 12:01 PM Tens um namespace e uma class dentro de outra class... 🙂 There are two ways to write error-free programs; only the third one works. Link to comment Share on other sites More sharing options...
cagueca Posted March 12, 2009 at 01:00 PM Author Report Share #250238 Posted March 12, 2009 at 01:00 PM Ou seja vou ter que tirar uma das cass .. ??? Link to comment Share on other sites More sharing options...
Hellblazer Posted March 12, 2009 at 01:01 PM Report Share #250240 Posted March 12, 2009 at 01:01 PM Podes ter as duas classes tem e de estar uma fora da outra lol Repara que estamos a falar ai de dois windows forms difrentes 🙂 There are two ways to write error-free programs; only the third one works. Link to comment Share on other sites More sharing options...
cagueca Posted March 12, 2009 at 05:20 PM Author Report Share #250322 Posted March 12, 2009 at 05:20 PM Boas : E se eu quiser ficar so com uma form como faco para tirar uma e ficar com a wififind ?? Link to comment Share on other sites More sharing options...
jpaulino Posted March 12, 2009 at 05:44 PM Report Share #250325 Posted March 12, 2009 at 05:44 PM Mas o que é que estás a tentar fazer ? A estrutura deve ser esta: Namespace ABC Class A ' codigo End Class Class B ' codigo End Class End Namespace Namespace DEF Class C ' codigo End Class End Namespace Link to comment Share on other sites More sharing options...
Hellblazer Posted March 12, 2009 at 05:46 PM Report Share #250329 Posted March 12, 2009 at 05:46 PM jpaulino o problema e que ambas as classes que ele ali tem sao windows forms 🙂 A class que tu queres , referente ao form wififind é a que esta vazia 😕 There are two ways to write error-free programs; only the third one works. Link to comment Share on other sites More sharing options...
jpaulino Posted March 12, 2009 at 05:52 PM Report Share #250333 Posted March 12, 2009 at 05:52 PM jpaulino o problema e que ambas as classes que ele ali tem sao windows forms 🙂 A class que tu queres , referente ao form wififind é a que esta vazia 😕 Está é uma confusão 👍 Link to comment Share on other sites More sharing options...
cagueca Posted March 12, 2009 at 06:07 PM Author Report Share #250341 Posted March 12, 2009 at 06:07 PM ? pois acredito que esteja confuso ... loool vou ver e ja digo algo Obrigado Edit : Bem acho que vou desistir e tentar fazer coisas mais faceis ... Um obrigado pela ajuda que deram . Abraco Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now