您的位置:程序门 -> .net技术 -> vb.net



vb中定长string类型在vb.net中怎样改?


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


vb中定长string类型在vb.net中怎样改?[已结贴,结贴人:cruiser332]
发表于:2007-04-27 11:14:06 楼主
vb中如下定义:
type   user_inf                      
        control_sv_name           as   string   *   16            
        exepath                           as   string   *   128          
        oraclehost                     as   string   *   16            
        oracleuid                       as   string   *   8              
        oraclepassword             as   string   *   16            
        oracletbluid                 as   string   *   8              
        excel_reportpath         as   string   *   128          
        shortbcr_exepath         as   string   *   128          
        shortbcr_datapath       as   string   *   128          
        longbcr_exepath           as   string   *   128          
        longbcr_datapath         as   string   *   128        
end   type

我在vb.net中改成如下来用,是否可以
structure   user_inf                      
                        dim   control_sv_name   as   string              
                        dim   exepath   as   string            
                        dim   oraclehost   as   string              
                        dim   oracleuid   as   string                
                        dim   oraclepassword   as   string              
                        dim   oracletbluid   as   string                
                        dim   excel_reportpath   as   string            
                        dim   shortbcr_exepath   as   string            
                        dim   shortbcr_datapath   as   string            
                        dim   longbcr_exepath   as   string            
                        dim   longbcr_datapath   as   string            
end   structure

上面的使用可行吗?先谢谢大家帮忙啦
发表于:2007-04-27 11:17:261楼 得分:8
<marshalas(unmanagedtype.byvaltstr,   sizeconst:=16)>   _
dim   control_sv_name   as   string
发表于:2007-04-27 11:49:512楼 得分:0
楼上的使用方法是否需要引入什么?
我用时说unmanagedtype没有定义。
谢谢。
发表于:2007-04-27 11:56:063楼 得分:0
system.runtime.interopservices
发表于:2007-04-27 12:44:024楼 得分:4
参考下面的帖子
http://community.csdn.net/expert/topic/5376/5376725.xml?temp=1.200503e-02
发表于:2007-04-27 14:07:065楼 得分:0
楼上两位的方法我都试过了,不过似乎和vb所要实现的不一样。
vb中使用定长字符串,如果赋值超过指定长度,会将剩余部分截去的。楼上方法都试过了,指定了16的长度,赋值20位后并没有截取前16位,而是全部显示。
发表于:2007-04-27 14:13:056楼 得分:0
我搜过了,下面方法都用在c#中,vb.net中怎么不好使啊
<marshalas(unmanagedtype.byvaltstr,   sizeconst:=16)>   _
dim   control_sv_name   as   string
发表于:2007-04-27 15:57:137楼 得分:0
很简单啊   ,有一个类可以转换的。联系我   654645788
发表于:2007-04-28 09:06:398楼 得分:0
晕,我不上qq

有没有其他办法啊,大家帮帮忙
发表于:2007-04-28 10:53:159楼 得分:8
structure   user_inf                      
                        dim   control_sv_name   as   string              
                        dim   exepath   as   string            
                        dim   oraclehost   as   string              
                        dim   oracleuid   as   string                
                        dim   oraclepassword   as   string              
                        dim   oracletbluid   as   string                
                        dim   excel_reportpath   as   string            
                        dim   shortbcr_exepath   as   string            
                        dim   shortbcr_datapath   as   string            
                        dim   longbcr_exepath   as   string            
                        dim   longbcr_datapath   as   string            
end   structure


dim   obj1   as   user_inf
with   obj1
.control_sv_name=space*16
.exepath=space*128
end   with
其它类同
发表于:2007-04-28 11:10:0110楼 得分:0
楼上这个应该改成:
dim   obj1   as   user_inf
with   obj1
.control_sv_name=space(16)
.exepath=space(128)
end   with
确实分配了16的空间,可要是给control_sv_name赋20位,则显示为20位,不是16位。
现在需要是分配16长度,如果超出则最大显示16位。
没有其他的办法了么?
发表于:2007-04-29 09:16:0711楼 得分:0
结构中还是不能使用定长字符串
不过还是感谢大家帮忙,结帖拉


快速检索

最新资讯
热门点击