VB6.0からVB2008移植時のStringの使用方法

このQ&Aのポイント
  • VB6.0からVB2008にプログラムを移植する際のStringの使用方法について教えてください。
  • VB6.0からVB2008の移植作業を行っていますが、特定の部分の修正方法がわかりません。具体的には、strStartに値を設定する際にエラーが発生しています。
  • VB自体はまだ初心者であり、勉強する時間もないため、修正方法についてお知恵を拝借したいです。どのようにstrStartを設定すれば良いでしょうか?
回答を見る
  • ベストアンサー

VB6.0からVB2008移植時のStringの使用方法

初歩的な質問だと思うのですが色々調べてもわからなかったのでご教授願います。 VB6.0からVB2008にプログラムを移植しているのですが以下の部分の修正方法がわかりません。 元(VB6.0)のソース Dim strStart, strEnd As String strStart = Format( data.Start(0), "0.0" ) strEnd = Format( data.End(0), "0.0" ) Label.Caption = strStart & "-" & strEnd 'data.Start/data.EndはSingleの配列 VB2008のソース Dim strStart As String Dim strEnd As String strStart = VB6.Format( data.Start(0), "0.0" ) strEnd = VB6.Format( data.End(0), "0.0" ) Label.Caption = strStart & "-" & strEnd 'VB6.Format~はソースをUpGradeしたときに自動で変換されました VB2008のstrStartに設定する時点でエラー('System.NullReferenceException' の初回例外が DataRcvSample.exe で発生しました。)となりstrStartがNothingなのがいけないところまではわかったのですが、Newを使ってどのように設定すればいいのかがわかりません。 VB自体まだ2週間位しか触っていない初心者なのですが、急ぎの仕事で勉強する時間がなく、どうすればいいのか困っています。 修正方法をご教授願います。

質問者が選んだベストアンサー

  • ベストアンサー
回答No.1

strStart = data.Start(0).ToString("#0.0") strEnd = data.End(0).ToString("#0.0") こんな感じでいかがでしょう?

MOYAJI
質問者

お礼

設定できました。 Wizard_Zeroさんありがとうございました。

関連するQ&A

  • PICNICのVB制御プログラム

    お世話になります。 VBでPICNICボード(トライステート社製http://www.tristate.ne.jp/)の制御ソフトを作っているのですがコンパイルエラーがでて、プログラムの実行ができません。(VB初心者です) (1)接点入力、アナログデータは取り込みできます。 (2)パラレルポートのピン方向制御はできます。 (3)パラレルポートのピン方向状態は読み込みできます。 (4)接点出力(I/O pinのLow,High)制御、液晶制御、RS232送信制御ができません。 問題ありソース Dim retvalue As Variant Dim n, m As Integer Dim nameb As String Dim rez As Integer Dim status(0 To 3) As Boolean Dim current As Integer Dim data(100000) As Integer Dim datab(100000) As Boolean Private Sub Command1_Click() data(current) = PICOCX1.ADinp(PortA, 4) Label1.Caption = "温度:" & Format(data(current) / 10.23 * 5, "#0.0℃") retvalue = PICOCX1.Dirp(PortB, 4, pinOutput) End Sub Private Sub Command2_Click() Unload Me End Sub Private Sub Timer1_Timer() Call check End Sub Private Sub check() n = 0 m = 0 nameb = "tanaka" data(current) = PICOCX1.ADinp(PortA, 0) Label2.Caption = "温度:" & Format(data(current) / 102.3 * 5, "#0.0℃") data(current) = PICOCX1.ADinp(PortA, 1) Label3.Caption = "湿度1:" & Format(data(current) / 10.23 * 5, "#0.0%") data(current) = PICOCX1.ADinp(PortA, 2) Label4.Caption = "湿度2:" & Format(data(current) / 10.23 * 5, "#0.0%") data(current) = PICOCX1.ADinp(PortA, 3) Label5.Caption = "空き:" & Format(data(current) / 10.23 * 5, "#0.0") data(current) = PICOCX1.ADinp(PortA, 5) Label6.Caption = "温度:" & Format(data(current) / 10.23 * 5, "#0.0℃") 'ポートRA5の値 基板側のミス? data(current) = PICOCX1.ADinp(PortA, 4) Label1.Caption = "温度:" & Format(data(current) / 10.23 * 5, "#0.0℃") ' 文法テスト datab(10000) = PICOCX1.ADinp(PortA, 4) '接点入力状態 status(0) = PICOCX1.Inp(PortB, 0) If status(0) = True Then Label7(0).Caption = "扉閉状態" Else Label7(0).Caption = "扉開状態" End If status(1) = PICOCX1.Inp(PortB, 1) If status(1) = True Then Label7(1).Caption = "扉施錠状態" Else Label7(1).Caption = "扉解除状態" End If status(2) = PICOCX1.Inp(PortB, 2) If status(2) = True Then Label7(2).Caption = "  " Else Label7(2).Caption = "人検知" End If status(3) = PICOCX1.Inp(PortB, 3) If status(3) = True Then Label7(3).Caption = "High" Else Label7(3).Caption = "Low" End If 'パラレルポート入出力状態 retvalue = PICOCX1.GetDirp(PortB, 4) 'パラレルポート入出力方向制御 'retvalue = PICOCX1.Dirp(PortB, 4, pinInput) ' retvalue = PICOCX1.Dirp(PortB, 4, pinOutput) '接点出力制御 'data(current) = PICOCX1.Outp(PortB, 4, High) 'void = PICOCX1.Outp(PortB, 4, High) 'retvalue = PICOCX1.Outp(PortB, 4, 0) retvalue = PICOCX1.Outp(PortB, 4, High) '液晶の制御 ' retvalue = PICOCX1.LcdClear これはサポートされていなとのメッセージ 'retvalue = PICOCX1.ClearLcd '型の不一致エラー ' retvalue = PICOCX1.PutLcd(n, m, nameb) 'retvalue = PICOCX1.SetPos(n, m) 'retvalue = PICOCX1.PutLcd(n, m, nameb) 'シリアルI/F制御 'retvalue = PICOCX1.Transmit(nameb) retvalue = PICOCX1.Receive '文法エラーでなく誰かがすでに使用しているとのメッセージ End Sub エラー内容及び疑問 (1) 接点出力制御 retvalue = PICOCX1.Outp(PortB, 4, High)   コンパイルエラー 型が一致しません。 とのエラーがでます。基本的文法ミスですか? retvalue を全種10種に型に変更しても変わりません。 (2) retvalue = PICOCX1.Outp(PortB, ・・とエディターで入力時、ADinp命令入力時みたいに入力支援メニュで型宣言がありません。型指定不要ですか? 以上 初歩的質問ですが、悩んでおります。 お忙しいところ申し訳ありませんが誰か教えてください。

  • VB6 Form内のDragDrop

    VB6でForm内にCommandButtonがいくつか有ります。 各CommandButtonはClickするとShellオブジェクトでファイルを開く様になっています。 やりたいことは 2つのCommandButton間をDragDrop?によりCaptionを入れ替えたいです。 (CommandButton間をマウスDragDropでCaption名入れ替え) MouseDownとDragDropイベントで何とかなると思いましたがうまくいきません。 Dim dd As Integer Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = vbLeftButton Then dd = 1 'CommandボタンNo, End If End Sub Private Sub Command2_DragDrop(Source As Control, X As Single, Y As Single) Dim cn As String cn = Command2.Caption Command2.Caption = Controls("Command" & dd).Caption Controls("Command" & dd).Caption = cn End Sub CommandButtonプロパティでDragModeを自動にするとShellオブジェクトでファイルが開かないし サイトで調べたところファイルの移動やコマンド自体の移動などで分かりませんでした。 ご教授お願い致します。

  • [VB6]文字列でオブジェクトを指定する方法

    VB6でiniファイルからリードしたフォーム名を元に そのフォームをロードしたいのですが、出来ますでしょうか? 以下のソースで★ところのコメントがしたいのです。 '--------------- Type HogeType testform as Form caption as String End Type Dim FormTest(2) as HogeType Private Sub SetFormData() Set FormTest(0).testform = Form1 '★←ここを"Form1"とか文字列が格納された変数としたい。 FormTest(0).caption = "test1" End Sub Private Sub Main() FormTest(0).Show End Sub 以上、宜しくお願い致します。

  • うまくVBが組めません

    会社でエクセルを使ってデータをまとめているのですがVBのユーザーフォームで作ろうとしています。今困っていることはoptionbuttonを4個使い選択式にし、選択したら「OK」buttonを押すことで各optionbuttonに対応したsheetへ飛ぶようにしたいのですがうまくいきません。 現状ですが Private Sub CommandButton1_Click() dim str as string str=optionbutton1.caption select case str case "****" sheets("1234").select ・    ・    ・ end select End Sub としています。 根本的に違うかもしれないので指摘してください。 ちなみに3日前に始めてVBを教えてもらいました。

  • VB6.0のString関数に代わるVB2008のそれは?

    2009年1月27日にVB 2008Expressをダウンロードしたばかりの初学者です。 ですから、色々とわからないことだらけです。 で、今回は VB6.0のString関数に代わるVB2008のそれ。 ? String(12, "*") ************ Function Strings(ByVal C As Char, ByVal L As Integer) As String   Return Space(L).Replace(" ", C) End Function 少しは探しましたが、適当なのがなくてStrings関数を作成してしまいました。 2週間程度の初学者。 しかも、文字列関連のヘルプは昨日に初めて紐解いたばかり。 ですから、「適当なのがない」との判断はかなり怪しいものです。 そこで、「VB6.0のString関数に代わるVB2008のそれは、これですよ!」という回答をお願いします。

  • VB6のTYPE文をVB.NETのStructureに変えるとき

    VB6のTYPE文をVB.NETのStructureに変えるとき 下記VB6のコードをVB.NETのStructureに変える場合 Type kouzou1 i As Integer j As Integer a As String * 20 b As String * 50 End Type を下記にしてみたのですが *20,*50のところは、どのように表現するのでしょうか。 Structure kouzou1 Dim i As Integer Dim j As Integer Dim a As String * 20 <- ステートメントの終わりを示してくださいのエラーになる。 Dim b As String * 50 <- ステートメントの終わりを示してくださいのエラーになる。 End Structure お教え下さい。

  • VB6では、Applicationは未定義なのでしょうか?

    VB6を使ってプログラムを書いているのですが、以下のソースの部分で エラーになりました。 Dim winname As String winname = Application.Caption <-- Applicationが未定義?  コンパイルエラー 変数が定義されていません。 というエラーメッセージが表示されます。 VB6では、Applicationは未定義なのでしょうか?

  • VBのString型の配列をVCで受け取るには?

    VBでString型の配列として定義されている変数を VCのプログラムで受け取るにはどうすればよいのでしょうか? 試しにVBでString型の配列を作って DLLのC_TESTというファンクションを呼び出すという 処理を作ってみたのですが、コンパイルエラーになってしまいます。 なにかおかしいところありますか? そもそもVCにはString型ってないんですよね? プログラミング初心者ですので、変な言葉遣いに なってるかもしれませんが宜しくお願いします。 VB Declare Function C_TEST Lib "\test.dll" (ByVal data() As String) As Integer Dim A(1) As String dim rtn as Integer A(0)="あああ" A(1)="いいい" rtn= C_TEST(A) VCのプログラム int _stdcall C_TEST(LPSTR A[2] ){ AfxMessageBox( A[0] ); return(0); }

  • VB、教えてください。

    VB、教えてください。 5つのラベルが縦に並んでいます。 label0 label1 label2 label3 label4 あらかじめ、 Dim m as integer=0 を宣言し、 どうにかして "label"という文字列とmという数字をくっつけ、 label0 label1… という風にできないでしょうか。 そして label"m".text=10*m というような表示を作りたいのですが。 下記のようなイメージです。分かりにくかったらごめんなさい。 Public Class Form1 Dim m As Integer = 0 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click lblmessage(+("m").Text = 10*m m = m + 1 End Sub End Class

  • vb6.0のプログラム

    今こんなプログラムを作っているのですがなぜか、足りない部分があると言われて困っております。 できれば教えてください。 図 ーーーーーーーーーーーーーーーー from ーーーーーーーーーーーーーーーー 残り30秒[ーーーーラベルーーーー] 000+000=000←(3つともlabel) □-------------------□←HScrollbar max100 min0 [コマンドボタン] [タイマー]←非表示 ーーーーーーーーーーーーーーーー コード Private intCount As Integer Private intSecond As Integer Private Sub cmdStart_Click() Dim intNum1 As Integer Dim intNum2 As Integer If cmdStart.Caption = "Start" Then intCount = 0 intSecond = 30 lblResult.Caption = "" cmdStart.Caption = "OK" tmrSecond.Enabled = True ElseIf cmdStart.Caption = "OK" Then If CInt(lblAnswer.Caption) = CInt(lblNum1.Caption) + CInt(lblNum2.Caption) Then lblResult.Caption = lblResult.Caption & "○" intCount = intCount + 1 Else lblResult.Caption = lblResult.Caption & "×" End If intNum1 = Rnd() * 50 intNum2 = Rnd() * 50 lblNum1.Caption = intNum1 lblNum2.Caption = intNum2 End If End Sub Private Sub hsbAnswer_Change() lblAnswer.Caption = hsbAnswer.Value End Sub Private Sub tmrSecond_Timer() intSecond = intSecond - 1 lblTime.Caption = "残り" & intSecond & "秒" If intSecond = 0 Then tmrSecond.Enabled = False MsgBox (intCount & "問正解") cmdStart.Caption = "Start" Else End If End Sub どうぞよろしくお願いします。