AJUDA WB

BETOPSY 07/03/2015 16:24:12
#445061
Bom dia , gostaria de pegar um testo no site , ex
se o texto for [Ô]a vida e bela [Ô] ir para o site 1
se o texto for [Ô] a vida nao ta boa[Ô] ir para o site 2

porem os 2 textos estao na fonte do site
quando uso o comando
If InStr(wbtestador.Document.Body.InnerText, [Ô]a vida e bela[Ô] then

ele ja pega , entao gostaria de pegar apenas quando aprecer no wb nao dentro da fonte
aguem tem ideia de como fazer?
BETOPSY 09/03/2015 11:15:42
#445082
Alguem por favor?
ERINALDO 09/03/2015 13:13:35
#445086
VEJA ALGUNS EXEMPLOS: Fonte: google,MSDN


An If-statement uses the If-keyword and the Then-keyword. The ElseIf-statement has the [Ô]If[Ô] part capitalized in the middle. And the Else-statement has no [Ô]Then[Ô] part. We end with an [Ô]End If[Ô] statement.

Equals sign
Equals:
We do not use two equals signs together in an If-statement. We just use one.

Tip:
Visual Studio will automatically insert the [Ô]Then[Ô] and [Ô]End If[Ô] parts of an If-statement.

Based on:

.NET 4.5

VB.NET program that uses If, ElseIf and Else

Module Module1
Sub Main()

[ô] Get input.
Dim s As String = Console.ReadLine()

[ô] Check input with If, Elseif and Else.
If s = [Ô]cat[Ô] Then
Console.WriteLine([Ô]You like cats[Ô])
ElseIf s = [Ô]dog[Ô] Then
Console.WriteLine([Ô]You like dogs[Ô])
Else
Console.WriteLine([Ô]No choice made[Ô])
End If

End Sub
End Module

Output

dog
You like dogs
If Not
Not equal
An If-statement can also test a negative. Instead we must apply the Not-keyword. The If-statement then reads [Ô]If not this, then.[Ô] We also can apply the Not-keyword to the ElseIf clause.

Note:
We cannot use the [Ô]!=[Ô] operator. We must apply the Not-operator and then an equals expression.

VB.NET program that uses If Not

Module Module1
Sub Main()
[ô] An integer variable.
Dim i As Integer = 100

[ô] Test integer against 100 and 200.
If Not i = 100 Then
Console.WriteLine([Ô]i not 100[Ô])
ElseIf Not i = 200 Then
Console.WriteLine([Ô]i not 2[Ô])
End If

End Sub
End Module

Output

i not 2
And, Or
Syntax
With the [Ô]And[Ô]
and [Ô]Or[Ô] keywords,
we test complex expressions. These expressions are chained. If an expression with And, the first test that fails will cause the expression to be stopped.

And:
In the Or case, the first test that succeeds will cause the expression to be stopped (short-circuited).

Tip:
To use these binary (two-part) operators, we use the English words. This is a different syntax than [Ô]&&[Ô] and [Ô]||[Ô].

VB.NET program that uses And, Or

Module Module1

Sub Main()
Dim left As Integer = 10
Dim right As Integer = 100

[ô] Use [Ô]and[Ô] in expression.
If left = 10 And right = 100 Then
Console.WriteLine(1)
End If

[ô] Use [Ô]or[Ô] in expression.
If left = 5 Or right = 100 Then
Console.WriteLine(2)
End If
End Sub

End Module

Output

1
2
Boolean Function
Func keyword
An If-statement does not always directly test values. Sometimes it calls another Function and tests the value returned by that Function. In this example, the If-statement calls the IsValid Function.

Function
Bools: bits represented as zeros
Then:
The IsValid Function is evaluated. It returns True if the Integer argument is within a certain range.

Boolean
So:
If the Integer is within the specified range (10 to 100 inclusive) the inner block of the If-statement is reached.

VB.NET program that uses Function, If-statement

Module Module1

[ô][ô][ô] <summary>
[ô][ô][ô] See if size is valid.
[ô][ô][ô] </summary>
Function IsValid(ByVal size As Integer) As Boolean
[ô] Returns true if size is within this range.
Return size >= 10 And size <= 100
End Function

Sub Main()
[ô] Size variable.
Dim size As Integer = 50

[ô] Call IsValid function in an If-expression.
If IsValid(size) Then
Console.WriteLine([Ô]Valid size[Ô])
End If
End Sub

End Module

Output

Valid size
Locals
Cover logo
If-statements can become complex and hard to understand. It is sometimes possible to simplify them by adding local variables. Here we introduce a Boolean that stores whether the animal and size variables indicate a [Ô]big cat.[Ô]

Then:
We can test the isBigCat variable in the two If-statements. This reduces code repetition and makes the program easier to read.

Also:
In some programs, we can use this approach to reduce expensive method calls by storing their results for later reuse.

VB.NET program that tests local variable

Module Module1

Sub Main()
Dim animal As String = [Ô]cat[Ô]
Dim size As Integer = 10
Dim color As String = [Ô]grey[Ô]

[ô] Store expression result in local variable.
Dim isBigCat As Boolean = (animal = [Ô]cat[Ô] And size >= 8)

[ô] Test local variable.
If isBigCat And color = [Ô]grey[Ô] Then
Console.WriteLine(True)
End If

If isBigCat And color = [Ô]white[Ô] Then
Console.WriteLine(False)
End If
End Sub

End Module

Output

True
Select Case
Select method call
The If-statement is the most common selection statement in VB programs. But it is not our only choice. We can instead use the Select-Case statement. This compares a value against a set of constants.

Select Case
String
For strings, we also consider the Select-Case statement. This can lead to clearer syntax. But my experiments in VB.NET programs found that no advanced Dictionary-based optimizations were applied.

So:
Select Case on strings does not improve performance much over the If-statement in this language.

Performance
Squares: abstract
There are many ways to optimize an If-statement. Often program performance analysis is complex. And making your If-statements faster will help little. But these optimizations still have an effect.

1. Test common first.
If-statements are evaluated in sequential order. The most common cases should be tested first.

2. Select Case.
A Select-Case statement may improve performance. The Select-Case is implemented with a switch opcode.

Opcodes
3. Use Dictionary.
A Dictionary collection uses hash lookups to locate values. For large data sets, this is much faster.

Dictionary
4. Store results.
Assign the result of an expression to a variable. Then use that value, not complex If-statements, to test the condition.

Summary
The VB.NET programming language
If-statements are used throughout programs. They use a slightly different syntax form from many languages. We use the Not-keyword to test negatives for truth. And we end the statement block with an [Ô]End If[Ô] line.
BETOPSY 09/03/2015 13:33:15
#445087
Amigo ja avia visto todos os exemplos acima citados, pois procurei bastante antes de vir aqui criar um topico ,
Mas não entendi nada desses exemplos!

se alguem poder me ajudar!
BETOPSY 09/03/2015 13:53:15
#445088
Ex , o site , tem 2 respostas de acordo com o que e marcado ,
se vc marca a opçao 1 aparece a msg 1
se vc marca a opcao 2 aparece a msg 2

Ambas as messagens estao dentro da fonte do site,
mas eu quero pegar a mes que aparece de acordo com a opcao escolhida
mas quando uso
If InStr( ele pega direto dentro da fonte, mesmo nao aparecendo no wb ,isso que e o problema
eu gostaria de pegar a mes depois que ela fosse escolhida e aparecer no WB
pq as messagens ficao escondidas na fonte , e aperece depois que escolhe a opcao
FILMAN 09/03/2015 19:48:10
#445100
Tente usar o evento DocumentCompleted do webbrowser! Faça esse IF dentro desse evento!
BETOPSY 10/03/2015 02:54:09
#445108
Citação:

:
Tente usar o evento DocumentCompleted do webbrowser! Faça esse IF dentro desse evento!



algo desse tipo

If InStr(wbtestador.DocumentCompleted.Body.InnerText, [Ô]a vida e bela[Ô] then

??
pq se for nao da certo :(



PEGUDO 10/03/2015 11:50:02
#445123
Resposta escolhida
Primeiro fica difícil te ajudar sem saber de qual site você está querendo pegar estas informações.
Segundo: Precisamos saber se o controle de onde você quer buscar a informação possui id ou não, qual tipo de tag ele é (div, label, textbox, radio, etc)...

Um exemplo, no clique de um botão, seria (vamos supor que eu queira pegar o texto de uma div com id = divExemplo):

While Not WebBrowser1.ReadState = 4 [ô]Verifica se o WebBrowser já está carregado
Application.DoEvents
End While

Dim div As HtmlElement = WebBrowser1.Document.GetElementById([txt-color=#e80000][Ô]divExemplo[Ô][/txt-color])

MsgBox(div.InnerText)
BETOPSY 10/03/2015 12:42:09
#445125
essa e a fonte
<div class=[Ô]container ng-scope ng-hide[Ô] ng-controller=[Ô]ErrorMessageController[Ô] ng-show=[Ô]show_error_page[Ô]><div class=[Ô]error-page[Ô]><span>login erado verifique</span></div></div>
<div class=[Ô]container ng-scope ng-hide[Ô] ngs-controller=[Ô]MessageController[Ô] ngs-show=[Ô]show_page[Ô]><div class=[Ô]show-page[Ô]><span>login coreto</span></div></div>

O meu problema e que essa e a fonte, quando era o login , ele da a 1 msg
quando acerta ele da a 2 msg, eu gostaria de pegar a msg que aparece, na tela
ambas estao na fonte , mas o que eu preciso e de pegar apenas a que aparecer no wb ,
quando uso o comando
instr ele pega dentro da fonte ai nao da certo!

pq eu preciso fazer o seguinte , se o login for coreto ele pega a msg e da um comando
se o login for erado , ele pega a outra msg e da outro comando ,
PEGUDO 10/03/2015 13:07:48
#445128
Cara, se ambas aparecem no código fonte e você precisa só o que aparece no browser, faça o seguinte:
Dim exemplo As String = WebBrowser1.DocumentText

If exemplo.Contains([txt-color=#e80000][Ô]login errado verifique[Ô][/txt-color]) Then
[txt-color=#007100][ô]Código caso erro[/txt-color]
ElseIf exemplo.Contains([txt-color=#e80000][Ô]login correto[Ô][/txt-color]) Then
[txt-color=#007100] [ô]Código caso certo[/txt-color]
End If

BETOPSY 10/03/2015 16:06:51
#445134
Citação:

:
Cara, se ambas aparecem no código fonte e você precisa só o que aparece no browser, faça o seguinte:

Dim exemplo As String = WebBrowser1.DocumentText

If exemplo.Contains([txt-color=#e80000][Ô]login errado verifique[Ô][/txt-color]) Then
[txt-color=#007100][ô]Código caso erro[/txt-color]
ElseIf exemplo.Contains([txt-color=#e80000][Ô]login correto[Ô][/txt-color]) Then
[txt-color=#007100] [ô]Código caso certo[/txt-color]
End If





Nao deu certo , ele continua pegando dentro da fonte os 2 resultados :(
Página 1 de 2 [19 registro(s)]
Tópico encerrado , respostas não são mais permitidas