■93386 / ) |
Re[3]: 「接続文字列」を変数に格納 |
□投稿者/ KOZ (65回)-(2019/12/09(Mon) 13:27:34)
|
■No93382 (たかし さん) に返信
> 接続文字列 = Form1.接続文字列TextBox.Text
デフォルトのインスタンスを使ってますが、理解して使ってらっしゃいますか?
「My.Forms オブジェクト」
https://docs.microsoft.com/ja-jp/dotnet/visual-basic/language-reference/objects/my-forms-object
実行Button と同一のフォームに 接続文字列TextBox があるなら
接続文字列 = Me.接続文字列TextBox.Text
でいいですし、違うフォームなら
Dim 接続文字列 As String = String.Empty
For Each f As Form In Application.OpenForms
Dim f1 As Form1 = TryCast(f, Form1)
If f1 IsNot Nothing Then
接続文字列 = f1.接続文字列TextBox.Text
If Not String.IsNullOrEmpty(接続文字列) Then
Exit For
End If
End If
Next
とインスタンスを検索したり、あらかじめ、実行Button_Click からアクセスできる範囲に
Form1 のインスタンスを保持しておく必要があります。
|
|